
19 Jan
2009
19 Jan
'09
2:19 p.m.
template<class T> class lazy { public: explicit lazy(function<T ()> fetch) : _fetch(fetch) { }
T get() { if (!_cached) _cached = _fetch(); return _cached.get(); }
private: optional<T> _cached; function<T ()> _fetch; };
I miss a set function; e.g. from parser you get a string which is interpreted as a number and used, later changed/rewritten and saved (e.g. by use of spririt's Qi & Karma) as string again. Maybe another pattern for this use case is appropriate? Regards, Olaf