3#include <CesiumUtility/Assert.h>
4#include <CesiumUtility/Library.h>
25template <
typename TInput,
typename TDerivation>
31 using TOutput = std::invoke_result_t<TDerivation, TInput>;
38 : _derivation(derivation), _lastInput(), _lastOutput() {}
45 : _derivation(
std::move(derivation)), _lastInput(), _lastOutput() {}
58 if (input != this->_lastInput) {
59 this->_lastInput.emplace(std::forward<T>(input));
60 this->_lastOutput.emplace(this->_derivation(*this->_lastInput));
63 CESIUM_ASSERT(this->_lastOutput);
64 return *this->_lastOutput;
68 TDerivation _derivation;
69 std::optional<TInput> _lastInput;
70 std::optional<TOutput> _lastOutput;
78template <
typename TInput,
typename TDerivation>
82 std::is_invocable_r_v<
83 std::invoke_result_t<std::decay_t<TDerivation>, TInput>,
84 std::decay_t<TDerivation>,
86 "Callable provided to makeDerivedValue is not invocable with the "
89 std::forward<TDerivation>(derivation));
A function object that caches the last result of a derivation function based on its input....
TOutput operator()(T &&input)
Gets or computes the derived value.
DerivedValue(TDerivation &&derivation)
Constructs a new instance that will use the given derivation function.
std::invoke_result_t< TDerivation, TInput > TOutput
The type returned by the derivation function.
DerivedValue(const TDerivation &derivation)
Constructs a new instance that will use the given derivation function.
Utility classes for Cesium.
auto makeDerivedValue(TDerivation &&derivation) -> DerivedValue< TInput, std::decay_t< TDerivation > >
Helper factory to construct a DerivedValue while specifying only the input type explicitly and lettin...