PicoScenes API Docs
 
Loading...
Searching...
No Matches
Singleton.hxx
Go to the documentation of this file.
1//
2// Singleton.hpp
3//
4// Created by JiangZhping on 2017/2/1.
5// Copyright © 2017年 JiangZhping. All rights reserved.
6//
7
8#ifndef Singleton_hpp
9#define Singleton_hpp
10
11#include <cstdio>
12
13template<class T>
14class Singleton {
15public:
16 template<typename... Args>
17 static T &getInstance(Args... args) {
18 if (!m_pInstance) [[unlikely]] {
19 m_pInstance = new T(std::forward<Args>(args)...);
20 }
21
22 return *m_pInstance;
23 }
24
25protected:
27
29
30private:
31 Singleton(Singleton const &);
32
33 Singleton &operator=(Singleton const &);
34
35 static T *m_pInstance;
36};
37
38template<class T> T *Singleton<T>::m_pInstance = nullptr;
39
40
41#endif /* Singleton_hpp */
static T & getInstance(Args... args)
Definition Singleton.hxx:17