Template Class Susp

Inheritance Relationships

Base Type

Class Documentation

template<class T>
class Susp : public otyca::SuspBase

Suspended (lazy) evaluation wrapper with memoization and dependency tracking.

Template Parameters:

T – The type of value being lazily computed.

Public Functions

inline Susp(const std::function<void(T&)> &updater)

Constructs a Susp with a custom updater function.

Parameters:

updater – Function that computes or updates the value.

inline Susp()

Constructs a Susp with a default no-op updater.

inline T &as_is() const

Returns the memoized value without checking validity.

Returns:

Reference to the memoized value.

inline T const &force_update_and_get() const

Forces update of the memoized value and returns it.

Returns:

Const reference to the updated value.

inline T const &get() const

Returns the value, computing it if not valid.

Returns:

Const reference to the current or updated value.

inline operator T const&() const

Allows implicit conversion to the value type.

Returns:

Const reference to the value.

inline bool valid() const

Checks if the current value is valid (up-to-date).

Returns:

True if valid, false if invalidated.

inline virtual void reset() const override

Invalidates the current value and recursively resets dependents.

inline void reset_dependents_if_changed()

Conditionally resets dependents if the updated value differs from the current one.

inline void set(const T &t)

Sets the memoized value and resets dependents.

Parameters:

t – New value to set.

inline void set_updater(const std::function<void(T&)> &updater)

Sets the updater function used to recompute the value.

Parameters:

updater – New updater function.