template Singleton(T) { private static T _instance; private static bool _deleted = false; public static T get() { assert(!_deleted); if (_instance is null) { _instance = new T(); } return _instance; } public static void destroy() { assert(!_deleted); delete _instance; _deleted = true; _instance = null; } } unittest { class Foo { mixin Singleton!(Foo); private this() { printf("Constructor!"); } } Foo a = the!(Foo)(); Foo b = the!(Foo)(); assert(a is b); } // best global symbol name ever template the(T) { T the() { return T.get(); } }