I am trying to create and then check the list of types registered at compile time and then create and serve instances of those types from templated functions. As an example:
class Widgets
{
template<typename T>
void addWidget()
{
// register T in a type list at compile time here
}
template<typename T>
T& getWidget()
{
// compile time check to see if T is registered
// if registered then return a reference from a runtime map
}
void init()
{
// create a runtime type->instance map from registered types
}
}
// some where else in the code in a different class
SizeWidget& w = widgets.getWidget<SizeWidget>(); // this generates compiler error if SizeWidget is not registered
boost fusion looks like a good candidate for this except adding to the fusion map is immutable and returns a new type. This solution C++ type registration at compile time trick works but not from templated functions
Is this even possible?