10 template<
class T,
class Eval = function<
void(T&)>,
class Pred = function<
bool()>>
22 lazy(
const Eval& eval =
nullptr,
const Pred& pred =
nullptr)
23 : _dirty(true), _pred(pred), _eval(eval) {}
28 void setPred(
const Pred& pred) { _pred = pred; }
29 void setEval(
const Eval& eval) { _eval = eval; }
32 const T&
raw()
const {
return _val; }
33 T&
raw() {
return _val; }
41 operator const T&()
const {
return get(); }
42 operator T&() {
return get(); }
45 template<
class... Args>
46 T&
get(Args&&... args)
49 if (!(
isDirty() || (_pred && _pred(args...))))
return _val;
55 template<
class... Args>
56 const T&
get(Args&&... args)
const {
return const_cast<lazy*
>(
this)->
get(forward<Args>(args)...); }
71 typedef decltype(eval()) R;
72 return lazy<R>([=](R& val)
mutable { val = eval(); });
lazy(const Eval &eval=nullptr, const Pred &pred=nullptr)
Definition: Lazy.h:22
A thread lock where the lock is acquired through a busy wait loop.
Definition: Spin.h:17
Wraps a value so that it is calculated only when needed. A lock synchronizes access.
Definition: Lazy.h:11
auto lazyCreate(Eval &&eval) -> lazy< decltype(eval())>
Create a lazy value from a function that returns a value. Ex. auto lazy = lazyCreate([] { return T();...
Definition: Lazy.h:69
bool isDirty() const
Definition: Lazy.h:26
void setDirty(bool dirty)
Definition: Lazy.h:25
T & operator*()
Definition: Lazy.h:37
T & raw()
Definition: Lazy.h:33
static auto _
Definition: Module.cpp:8
T * operator->()
Definition: Lazy.h:39
void setPred(const Pred &pred)
Definition: Lazy.h:28
const T * operator->() const
Definition: Lazy.h:38
void setEval(const Eval &eval)
Definition: Lazy.h:29
const T & operator*() const
Evaluate the lazy value.
Definition: Lazy.h:36
const T & raw() const
Direct access to the wrapped value (ie. does not evaluate)
Definition: Lazy.h:32
Global Honeycomb namespace.