I have some auto generated structs each logically related to a enum value. can I create a factory using a template function? everything can be resolved at compiled time. I tried something like this:
struct Type1
{
};
struct Type2
{
};
enum class type_t
{
first,
second
};
template <type_t typet>
auto Get_()
{
static_assert(typet == type_t::second);
return Type2();
}
template <type_t typet>
auto Get_()
{
static_assert(typet == type_t::first);
return Type1();
}
template <type_t typet>
auto Get_()
{
static_assert(false, "no overload");
}
int main()
{
auto relatedType1 = Get_<type_t::first>();
auto relatedType2 = Get_<type_t::second>();
}