Created
April 4, 2017 04:03
-
-
Save russleyshaw/650d94ed653a52f96273667b2b8eb25b to your computer and use it in GitHub Desktop.
Converts class enum to underlying type.
This file contains 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
#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