I am aware of the Meyers singleton:
class Singleton{
private:
Singleton();
public:
Singleton & GetInstance(){
static Singleton instance;
return instance;
}
}
The advantages of it is that it uses lazy evaluation but it is not guaranteed to be thread-safe in C++ 03.
What if the static instance is a member variable? Is that guaranteed to be thread-safe? I don't see why not. Moreover I'm willing to give up the lazy instantiation for that.
class Singleton{
private:
Singleton();
static Singleton instance;
public:
Singleton & GetInstance(){
return instance;
}
}