I have got a template function that currently looks like this :
#include <string>
enum class Enum { EVENT_ONE, EVENT_TWO };
template<Enum e, typename T>
void MyFunc() { }
int main(int argc, const char* argv[])
{
MyFunc<Enum::EVENT_ONE, int>();
MyFunc<Enum::EVENT_TWO, std::string>();
}
I would like to create some constant mapping between enum class, and the typename template, in order to make it simpler.
Ideally, this method should get only the enum as a template, and the typename template will be somehow resolved using the predefined mapping.
int main(int argc, const char* argv[])
{
MyFunc<Enum::EVENT_ONE>();
MyFunc<Enum::EVENT_TWO>();
}
Is it possible in modern C++ (C++17 or C++20) ?