
Stefan Slapeta wrote:
I can ... a little static helper class is very helpful in this situation (I posted it some time ago to the list):
//////////////////////////////////////// // class template static_ //////////////////////////////////////// template <typename T, typename OwnerT = void> struct static_ { T* operator -> () const { return &member; }
static T* get() { return &member; }
private: static T member; };
template <typename T, typename OwnerT> T static_<T, OwnerT>::member;
///////////////
This way you can declare a global static instance of a type from anywhere in the code, i.e. in header files, because templates show a different behaviour for static members.
This is a really nice trick! However a question: Is it guaranteed by the standard, that the ctor of the "member" is beeing called at program startup? Perhaps thread_specific_ptr itself should be implemented by means of this idiom then? Roland