pImpl
pImpl Idiom in C++
Loading...
Searching...
No Matches
singleton.h
1/*
2 Copyright (c) 2023, Pascal JEAN aka epsilonrt
3 All rights reserved.
4
5 SPDX-License-Identifier: BSD-3-Clause
6*/
7
8#ifndef DOXYGEN
9#define SINGLETON_I(Class) Class & i = Class::instance()
10#endif // DOXYGEN
11
29template<typename T>
30class Singleton {
31 public:
37 static T &instance();
38
42 Singleton (const Singleton &) = delete;
46 Singleton &operator= (const Singleton) = delete; // non copyable
47
48 protected:
50};
51
52template<typename T>
54 static T instance;
55 return instance;
56}
57
58#ifdef DOXYGEN
64#define SINGLETON_I(Class)
65#endif // DOXYGEN
Singleton class.
Definition singleton.h:30
Singleton(const Singleton &)=delete
Make the class non construction-copyable and non copyable.
static T & instance()
Get the instance object.
Definition singleton.h:53
Singleton & operator=(const Singleton)=delete
Make the class non copyable.