cesium-native 0.52.0
|
A function object that caches the last result of a derivation function based on its input. This is sometimes called "memoization", but this simple implementation only remembers the result of a single past invocation. More...
#include <CesiumUtility/DerivedValue.h>
Public Types | |
using | TOutput = std::invoke_result_t<TDerivation, TInput> |
The type returned by the derivation function. | |
Public Member Functions | |
DerivedValue (const TDerivation &derivation) | |
Constructs a new instance that will use the given derivation function. | |
DerivedValue (TDerivation &&derivation) | |
Constructs a new instance that will use the given derivation function. | |
template<typename T> | |
TOutput | operator() (T &&input) |
Gets or computes the derived value. | |
A function object that caches the last result of a derivation function based on its input. This is sometimes called "memoization", but this simple implementation only remembers the result of a single past invocation.
Please note that this class is not thread-safe.
TInput | The type of parameter passed as input to the derivation function. It must be possible (and, preferably, efficient) to compare instances of this type using operator!= . |
TDerivation | The type of the derivation function. This must be a callable type that takes a single parameter of type TInput and returns a non-void value. |
Definition at line 26 of file DerivedValue.h.
using CesiumUtility::DerivedValue< TInput, TDerivation >::TOutput = std::invoke_result_t<TDerivation, TInput> |
The type returned by the derivation function.
Definition at line 31 of file DerivedValue.h.
|
inline |
Constructs a new instance that will use the given derivation function.
Definition at line 37 of file DerivedValue.h.
|
inline |
Constructs a new instance that will use the given derivation function.
Definition at line 44 of file DerivedValue.h.
|
inline |
Gets or computes the derived value.
If this is the first time this method was invoked, or if the given input
is different from the last time this method was invoked (as indicated by operator!=
), the derivation function will be called to compute the derived value. The derived value will be cached and returned.
Otherwise, the previously-computed value will be returned.
Definition at line 57 of file DerivedValue.h.