Skip to content

Instantly share code, notes, and snippets.

@bolry
Created February 4, 2018 14:33
Show Gist options
  • Save bolry/ff8c3622a6beb167240d89ad83485771 to your computer and use it in GitHub Desktop.
Save bolry/ff8c3622a6beb167240d89ad83485771 to your computer and use it in GitHub Desktop.
Print enum i C++11 and later
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