cesium-native 0.52.0
Loading...
Searching...
No Matches
CesiumUtility::DerivedValue< TInput, TDerivation > Class Template Reference

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.
 

Detailed Description

template<typename TInput, typename TDerivation>
class CesiumUtility::DerivedValue< TInput, TDerivation >

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.

Template Parameters
TInputThe 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!=.
TDerivationThe 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.

Member Typedef Documentation

◆ TOutput

template<typename TInput, typename TDerivation>
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.

Constructor & Destructor Documentation

◆ DerivedValue() [1/2]

template<typename TInput, typename TDerivation>
CesiumUtility::DerivedValue< TInput, TDerivation >::DerivedValue ( const TDerivation & derivation)
inline

Constructs a new instance that will use the given derivation function.

Definition at line 37 of file DerivedValue.h.

◆ DerivedValue() [2/2]

template<typename TInput, typename TDerivation>
CesiumUtility::DerivedValue< TInput, TDerivation >::DerivedValue ( TDerivation && derivation)
inline

Constructs a new instance that will use the given derivation function.

Definition at line 44 of file DerivedValue.h.

Member Function Documentation

◆ operator()()

template<typename TInput, typename TDerivation>
template<typename T>
TOutput CesiumUtility::DerivedValue< TInput, TDerivation >::operator() ( T && input)
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.


The documentation for this class was generated from the following file: