Boost logo

Boost :

From: Stefan Slapeta (stefan_at_[hidden])
Date: 2005-01-20 08:11:35


Jonathan Wakely wrote:

>
> No. Unless the member is instantiated it will not be initialised. Since
> whether it is instantiated depends on whether you use it, which might
> depend on whether you've got testing/loggin/debugging code turned on,
> to guarantee that the member is initialised even when not used you might
> have to explicitly instantiate it for each specilalisation:
>
> template const int static_<int>::member = 0;
> template const bool static_<bool>::member = true;
>
>

If you ever access the member by calling static_<A>::get() in some piece
of _instantiated code_ it's guaranteed that static_<A>::member is going
to be instantiated (at program startup).

Of course, this is not the case for e.g. function templates that are
never instantiated or for inline functions that are not actually called.
However, I think it's rather a feature than a bug not to instantiate a
static_<A> member if the code is never executed.

Stefan


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