
Quoting Peter Dimov <pdimov@mmltd.net>:
... 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 wrappers: 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. B.