Wraps a value so that it is calculated only when needed. A lock synchronizes access.
More...
#include <Lazy.h>
|
(Note that these are not member functions.)
|
template<class Eval > |
auto | lazyCreate (Eval &&eval) -> lazy< decltype(eval())> |
| Create a lazy value from a function that returns a value. Ex. auto lazy = lazyCreate([] { return T(); }); More...
|
|
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
class honey::lazy< T, Eval, Pred >
Wraps a value so that it is calculated only when needed. A lock synchronizes access.
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
honey::lazy< T, Eval, Pred >::lazy |
( |
const Eval & |
eval = nullptr , |
|
|
const Pred & |
pred = nullptr |
|
) |
| |
|
inline |
- Parameters
-
eval | Function that will be called to evaluate the lazy value. A reference to the wrapped value is provided as the first arg. eval is called after the lock is acquired. |
pred | Optional predicate function to check if dirty. The lazy value is dirty if isDirty() or pred return true. pred is called once before (for early return) and once after the lock is acquired. Because pred is called on every access, it should use atomics and avoid locks. |
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class... Args>
T& honey::lazy< T, Eval, Pred >::get |
( |
Args &&... |
args | ) |
|
|
inline |
Evaluate the lazy value. Only evaluates if dirty. The args are passed to the predicate and eval function.
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class... Args>
const T& honey::lazy< T, Eval, Pred >::get |
( |
Args &&... |
args | ) |
const |
|
inline |
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
honey::lazy< T, Eval, Pred >::operator const T & |
( |
| ) |
const |
|
inline |
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
const T& honey::lazy< T, Eval, Pred >::operator* |
( |
| ) |
const |
|
inline |
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
const T* honey::lazy< T, Eval, Pred >::operator-> |
( |
| ) |
const |
|
inline |
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
Direct access to the wrapped value (ie. does not evaluate)
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
void honey::lazy< T, Eval, Pred >::setDirty |
( |
bool |
dirty | ) |
|
|
inline |
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
void honey::lazy< T, Eval, Pred >::setEval |
( |
const Eval & |
eval | ) |
|
|
inline |
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
void honey::lazy< T, Eval, Pred >::setPred |
( |
const Pred & |
pred | ) |
|
|
inline |
template<class Eval >
auto lazyCreate |
( |
Eval && |
eval | ) |
-> lazy<decltype(eval())>
|
|
related |
Create a lazy value from a function that returns a value. Ex. auto lazy = lazyCreate([] { return T(); });
The documentation for this class was generated from the following file: