Boost logo

Boost :

Subject: Re: [boost] utility class: lazy data type
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2009-01-19 09:19:36


> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk