Singleton template


#1

Hi guys,

Have anyone found a way to implement a singleton template?

header:
template <class T>
struct MySingleton
{
    ~MySingleton()
    {
        clearSingletonInstance();
    }
    
    JUCE_DECLARE_SINGLETON (MySingleton <T>, false)
};

cpp:
JUCE_IMPLEMENT_SINGLETON (MySingleton <T>) // error
JUCE_IMPLEMENT_SINGLETON (MySingleton) // error
JUCE_IMPLEMENT_SINGLETON (MySingleton <String>) // error

Thanks in advance!!

Cheers
Jelle


#2

No one who knows a solution for this…?


#3

It was never designed for templates, so I’m not really surprised. You could dig into the macros and see if there’s a way to tweak it to make it work, but it’s not something I’d want us to spend time on, as there are now better ways to do singletons nowadays, without macros, and we should probably at some point replace the old system altogether.