c++11单例模板类

#ifndef ITC_DAAS_SINGLETON_H_
#define ITC_DAAS_SINGLETON_H_

#include 
#include 

class Uncopyable {
protected:
    Uncopyable(){};
    ~Uncopyable(){};

private:
    Uncopyable(const Uncopyable& that);
    Uncopyable& operator=(const Uncopyable& that);
};

template 
class Singleton : public Uncopyable {
public:
    template 
    static T* getInstance(ArgTypes&&... args) {
        static std::once_flag of;
        std::call_once(
            of, [&]() { Singleton::instance_.reset(new T(std::forward(args)...)); });

        return instance_.get();
    }

private:
    static std::unique_ptr instance_;
};

template 
std::unique_ptr Singleton::instance_ = nullptr;


#endif

你可能感兴趣的:(c++学习拾荒)