Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2006-10-06 08:27:05

Quoting Peter Dimov <pdimov_at_[hidden]>:
> >
> > ... which will trigger static (thread-safe) initialization.
> This doesn't solve the initialization order problem, the primary reason for
> using local statics in the first place.

yup; Sam Saariste pointed it out in private discussion. What about having two

1. just like above, except for instead of direct data access I'd define inline
static function data() returning reference, class name would be more meaningful
(static_init_global) and it would accept additional two template parameters to
help guarantee uniqueness : type and pointer to that type (users would use it
eg. passing function type and address of that function)

2. another with identical signature (eg. two type parameters and a pointer, and
inline static function data() returning reference to first type) called
static_init_ordered that would implement singleton (presumably using double
checked idiom on platforms where it works)

The other one would guarantee initialization order at the extra performance cost
and could also forward arguments to the constructor. Alternatively, one could
use preprocessor and instead of delegating work to template, use some fancy
macro with proper synchronization etc.


Boost list run by bdawes at, gregod at, cpdaniel at, john at