Skip to content

Instantly share code, notes, and snippets.

@russleyshaw
Created April 4, 2017 04:03
Show Gist options
  • Save russleyshaw/650d94ed653a52f96273667b2b8eb25b to your computer and use it in GitHub Desktop.
Save russleyshaw/650d94ed653a52f96273667b2b8eb25b to your computer and use it in GitHub Desktop.
Converts class enum to underlying type.
#ifndef RUS_TO_UL_HPP
#define RUS_TO_UL_HPP
#include <type_traits>
/**
* Convert a class enumeration to its underlying type.
* Got tired of writing out static_casts and std::underlying type
* @param enumeration
* @return Value of enumeration
*/
constexpr auto to_ul(const auto enumeration) {
static_assert(std::is_enum<decltype(enumeration)>::value);
return static_cast< typename std::underlying_type<decltype(enumeration)>::type >(enumeration);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment