lumiera_documentation/research/clang-static-init.hpp
Ichthyostega 675b2070ce bughunt: attempt to rebuild the problematic structure stand-alone... --> MISS
this is only a stripped-down version of the basic singleton, without
the indirection. Unsurprisingly, this doesn't exhibit the problem yet
2013-10-06 23:17:18 +02:00

62 lines
798 B
C++

namespace test {
template<typename T
,template <class> class Fac
>
struct Holder
{
static T* instance;
T&
get()
{
if (!instance)
{
instance = Fac<T>::create();
}
return *instance;
}
};
template<typename T
,template <class> class F
>
T* Holder<T,F>::instance;
template<typename T>
struct Factory
{
static T*
create()
{
return new T();
}
};
struct Subject
{
static int cnt;
Subject();
};
typedef Holder<Subject,Factory> AccessPoint;
extern AccessPoint fab;
Subject& fabricate();
} // namespace test