I would like to replace big switch with something more elegant.
class Base
{
public:
Base(void*data, int size);
virtu
Something like this should work:
#include
You just need to add a single line to the factories list for each class.
If you are using an enum with contiguous values starting from 0 then you can just use an array rather than a std::map, e.g:
enum class Class
{
a,
b
};
Factory factories[] =
{
[]( void* data, int size ){ return std::make_unique( data, size ); },
[]( void* data, int size ){ return std::make_unique( data, size ); }
};
Class input = Class::a;
factories[static_cast(input)]( data, size )->Something();