I have some Signal prototype class
#include <map>
#include <string>
#include <functional>
template <class T>
class Signal
{
public:
std::function<T> slot;
};
Next comes template singleton SignalCollection
class, that automatically generates appropriate type for Signal
template <class T>
class SignalCollection
{
private:
SignalCollection() {}
SignalCollection(const SignalCollection&) = delete;
SignalCollection& operator= (const SignalCollection&) = delete;
public:
static SignalCollection& Instance()
{
static SignalCollection br{};
return br;
}
std::map<std::string, T> signals_map;
void add(T&& signal)
{
this->signals_map.insert(std::make_pair("a", std::forward<T>(signal)));
}
};
and last I have a function that deduces SignalCollection
type for some Signal
template<class T>
auto& get_collection_for_signal(T&& t)
{
return SignalCollection<T>::Instance();
}
The problem is, that I can't add values to the map of collection. Here is main:
void foo()
{
}
void main()
{
Signal<void()> sgl = Signal<void()>{}; //Create signal
sgl.slot = foo; //add slot
auto& t = get_collection_for_signal(sgl); //Get collection for this signal which is SignalCollection<Signal<void()>>
t.add(sgl); //error 1
t.signals_map["a"] = sgl; //error 2
}