00001 #ifndef toast_static_init_protected_hpp_INCLUDED
00002 #define toast_static_init_protected_hpp_INCLUDED
00003
00011 namespace toast {
00012 namespace detail {
00013
00014 template<class T, class unique_id>
00015 class static_init_protected
00016 {
00017 public:
00018 static T& get()
00019 {
00020 (void)private_guaranteed_init_hook_;
00021
00022
00023
00024
00025 static T the_object;
00026 return the_object;
00027 }
00028
00029 private:
00030 static_init_protected();
00031
00032 static bool private_guaranteed_init_hook_;
00033 };
00034
00035 template<class T, class unique_id>
00036 bool static_init_protected<T, unique_id>::private_guaranteed_init_hook_ =
00037 (static_init_protected<T, unique_id>::get(), true);
00038
00039 }
00040 }
00041
00128 #define TOAST_STATIC_INIT_PROTECTED(T, name) \
00129 struct private_dummy_toast_detail_nested_type_##name##__ {}; \
00130 typedef toast::detail::static_init_protected<T, private_dummy_toast_detail_nested_type_##name##__> name
00131
00134 #endif
00135