Bidirectional mapping between enum values and types
Recently, while working with a glue code integrating low level C APIs in C++ I stumbled upon a problem where I needed to map enum values to types (and vice-versa).
Problem definition
Imagine you’ve got a factory function:
|
|
Okay, so the create function must be a template but how to determine the
return type? Well, mapping from enum Types to any of the types is needed.
It’s easy to create one thanks to C++’s constant value template specialisation.
