Here is a mockable singleton using CRTP. It relies on a little helper to enforce a single object at any one time (at most). To enforce a single object over program execution, remove the reset (which we find useful for tests).
A ConcreteSinleton
can be implemented like this:
class ConcreteSingleton : public Singleton<ConcreteSingleton>{public: ConcreteSingleton(const Singleton<ConcreteSingleton>::PrivatePass&) : Singleton<StandardPaths>::Singleton{pass} {} // ... concrete interface int f() const {return 42;}};
And then used with
ConcreteSingleton::instance().f();