Is there a generic way to cast int
to enum
in C++
?
If int
falls in range of an enum
it should return an enum
value, otherwise throw an exception
. Is there a way to write it generically? More than one enum type
should be supported.
Background: I have an external enum type and no control over the source code. I'd like to store this value in a database and retrieve it.