Singleton rewrite based on old one
Toby Speight's answer is correct for a normal singleton, but the class that you're replacing doesn't look like a normal singleton.

The original class appears to allow the user to explicitly define the object lifetime. The static variable is actually just for ease of access to that object:


The new code changes the point of construction to the first call to Instance().
The point of destruction is changed from reverse-order of construction inside the owning scope, to reverse-order of construction when C++ cleans up static variables.


This may or may not matter to your use case, but note that these two factors combined can completely alter the order of destruction of your "singleton" objects.

If you want to keep managing the object lifetimes explicitly, it might be better to use something like the Service Locator pattern instead (which is closer to what the original code does).



A related example from my own code (the shared / weak ptrs could be replaced with raw pointers or some sort of handle):

template&lt;class T&gt;
class Service
{
public:

    static void Provide(std::weak_ptr&lt;T&gt; service)
    {
        if (Service::service.lock())
            throw std::runtime_error("Service is already being provided!");

        Service::service = service;
    }

    static void Stop()
    {
        Service::service = std::weak_ptr&lt;T&gt;();
    }

    static T&amp; Get()
    {
        auto strongService = service.lock();

        if (!strongService)
            throw std::runtime_error("Attempting to use a null service!");

        return *strongService;
    }

private:

    Service() = delete;

    static std::weak_ptr&lt;T&gt; service;
};

template&lt;class T&gt;
std::weak_ptr&lt;T&gt; Service&lt;T&gt;::service;