Created
February 4, 2018 14:33
-
-
Save bolry/ff8c3622a6beb167240d89ad83485771 to your computer and use it in GitHub Desktop.
Print enum i C++11 and later
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename OStream, typename Enum> | |
OStream& print_enum(OStream& os, Enum const e) | |
{ | |
static_assert(std::is_enum<Enum>::value, "not a enumerator"); | |
return os << static_cast<typename std::underlying_type<Enum>::type>(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment