Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-10-06 16:19:39


Roland Schwarz wrote:
> Anthony Williams wrote:
>> Roland Schwarz <roland.schwarz_at_[hidden]> writes:
>>> But I think your intent is: since we make the object appear like
>>> they are static, they should behave similar to real static objects.
>>> Correct?
>>
>> Yes, that's what I meant.
>
> Umm, than as I would say in germanish "we get into devils kitchen".

There is one interesting idiom that gets around the problem:

X* instance()
{
    static X x;
    return &x;
}

void f() // where the static would have been
{
    call_once( instance );
    X * px = instance();

    // use *px
}

It's made a bit easier if call_once is allowed to return a value... although
last time this was brought up this appeared a bit problematic to implement.

void f() // where the static would have been
{
    X * px = call_once( instance );
    // use *px
}

I wonder whether something similar can be "componentized" given an extended
call_once.


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