You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
542 B
C++

#ifndef BOOST_SINGLETON_H
#define BOOST_SINGLETON_H
template <typename T>
class Singleton
{
public:
static T & instance()
{
static T obj;
creator.do_nothing();
return obj;
}
private:
struct object_creator
{
object_creator()
{
Singleton<T>::instance();
}
inline void do_nothing() const { }
};
static object_creator creator;
};
template <typename T> typename Singleton<T>::object_creator Singleton<T>::creator;
#endif // BOOST_SINGLETON_H