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
29
template
<
typename
T>
30
class
Singleton
{
31
public
:
37
static
T &
instance
();
38
42
Singleton
(
const
Singleton
&) =
delete
;
46
Singleton
&
operator=
(
const
Singleton
) =
delete
;
// non copyable
47
48
protected
:
49
Singleton
() {}
50
};
51
52
template
<
typename
T>
53
T &
Singleton<T>::instance
() {
54
static
T instance;
55
return
instance;
56
}
57
58
#ifdef DOXYGEN
64
#define SINGLETON_I(Class)
65
#endif
// DOXYGEN
Singleton
Singleton class.
Definition
singleton.h:30
Singleton::Singleton
Singleton(const Singleton &)=delete
Make the class non construction-copyable and non copyable.
Singleton::Singleton
Singleton()
Definition
singleton.h:49
Singleton::instance
static T & instance()
Get the instance object.
Definition
singleton.h:53
Singleton::operator=
Singleton & operator=(const Singleton)=delete
Make the class non copyable.
src
singleton.h
Generated on Wed Aug 27 2025 14:23:08 for pImpl by
1.9.8