Skip to content

Instantly share code, notes, and snippets.

@TheEyesightDim
Last active July 1, 2018 08:26
Show Gist options
  • Save TheEyesightDim/6b50a5000c758bca0c36142350b4eb1c to your computer and use it in GitHub Desktop.
Save TheEyesightDim/6b50a5000c758bca0c36142350b4eb1c to your computer and use it in GitHub Desktop.
//this function converts any member of enum of any underlying type to that type.
//Effective Modern C++ by Scott Meyers. See item 10
template <typename E>
constexpr auto to_underlying(E e) noexcept
{
return static_cast<std::underlying_type_t<E>>(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment