|
Boost : |
From: Andrew J Bromage (ajb_at_[hidden])
Date: 2002-08-06 19:50:01
G'day all.
In retrospect I shouldn't have brought up a "more powerful"
call_once function, because that's not what I want at all. What
I "really" want is this:
class once
{
public:
once();
~once();
call_once(function0<void>&);
};
On Tue, Aug 06, 2002 at 09:13:26AM -0400, Pete Becker wrote:
> The one place where they seem useful is in lazy initialization. But rather
> than thinking in C terms and prolonging the life of the inside-out
> interface to once functions, think C++ and design a more suitable solution:
>
> class lazy_initializer
> {
> public:
> lazy_initializer();
> ~lazy_initializer();
> void init_once();
> private:
> virtual void do_init() = 0;
> };
This is in fact exactly what I wanted to use the once operation for,
except that my class needs more than one piece of data which is lazily
evaluated. Admittedly composing with more than one lazy_initializer
class would work, but it seems less clean than just dropping a few once
objects into the class.
Cheers,
Andrew Bromage
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk