关于C++实现的Singleton收集 2

boost的singleton

http://www.cnblogs.com/fullsail/archive/2013/01/03/2842618.html

http://leoxiang.com/dev/different-cpp-singleton-implementaion

View Code
// 实现基于以下假设:良好的设计在进入main函数之前应该是单线程的,
// 因此可以使用全局变量的方式来设计singleton,
// 并且保证在使用该singleton之前其已经被正确的初始化。
 
template <typename T>
class Singleton
{
public:
    struct object_creator
    {
        object_creator(){ Singleton<T>::instance(); }
        inline void do_nothing()const {}
    };
 
    static object_creator create_object;
 
    typedef T object_type;
 
    static object_type& instance()
    {
        static object_type obj;
        create_object.do_nothing();
        return obj;
    }
};
template <typename T> typename Singleton<T>::object_creator
Singleton<T>::create_object;

Loki 的singleton

http://hi.baidu.com/nzpwulrcdkfjovr/item/d08ead9a9327801c924f41c7

原文地址:https://www.cnblogs.com/logitechlike/p/2869053.html