Files
source/Tactical/LogicalBodyTypes/Singleton.h
T
fc1c1dfe77 remove stray 'typename' before non-qualified names
'typename' disambiguates a qualified dependent name, telling the
compiler that something like T::iterator names a type rather than a
value. Before a plain identifier there is nothing to disambiguate: P1
is already a type, and so is PopupIndex.

The grammar wants a qualified name after the keyword, so clang reports
"expected a qualified name after 'typename'", drops the keyword and
carries on -- 15175 times, since the offending declarations sit in
widely included headers. MSVC accepts them without a word.

Semantics do not change. Both compilers already ignored the keyword,
so the partial specialisations matched before this and match after it.

The diagnostic belongs to no -W group and therefore cannot be switched
off with -Wno-, which makes deleting the tokens the only way to quiet
it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 13:05:23 -03:00

80 lines
1.7 KiB
C++

#pragma once
#ifndef _LBT_SINGLETON__H_
#define _LBT_SINGLETON__H_
#include <cassert>
/*
Not thread safe. Copied from the codeproject (Author: Lai Shiaw San Kent)
*/
template<typename T> class ISingleton {
public :
static T& Instance();
};
template<typename T> class Singleton : public ISingleton<T> {
public :
static T& Instance();
static void Destroy();
protected :
inline explicit Singleton() {
assert(Singleton::instance_ == 0);
Singleton::instance_ = static_cast<T*>(this);
}
inline ~Singleton() {
Singleton::instance_ = 0;
}
private :
static T* CreateInstance();
static void ScheduleForDestruction(void (*)());
static void DestroyInstance(T*);
private :
static T* instance_;
private :
inline explicit Singleton(Singleton const&) {}
inline Singleton& operator=(Singleton const&) { return *this; }
};
template<typename T> T& Singleton<T>::Instance() {
if (Singleton::instance_ == 0) {
Singleton::instance_ = CreateInstance();
ScheduleForDestruction(Singleton::Destroy);
}
return *(Singleton::instance_);
}
template<typename T>
void Singleton<T>::Destroy() {
if (Singleton::instance_ != 0) {
DestroyInstance(Singleton::instance_);
Singleton::instance_ = 0;
}
}
template<typename T>
inline T* Singleton<T>::CreateInstance() {
return new T();
}
template<typename T>
inline void Singleton<T>::ScheduleForDestruction(void (*pFun)()) {
std::atexit(pFun);
}
template<typename T>
inline void Singleton<T>::DestroyInstance(T* p) {
delete p;
}
template<typename T>
T* Singleton<T>::instance_ = 0;
#endif