| 1 | #pragma once |
| 2 | |
| 3 | #include <type_traits> |
| 4 | |
| 5 | namespace sead |
| 6 | { |
| 7 | /// For storing an enum with a particular storage size when specifying the underlying type of the |
| 8 | /// enum is not an option. |
| 9 | template <typename Enum, typename Storage> |
| 10 | struct SizedEnum |
| 11 | { |
| 12 | static_assert(std::is_enum<Enum>()); |
| 13 | static_assert(!std::is_enum<Storage>()); |
| 14 | |
| 15 | constexpr SizedEnum() = default; |
| 16 | constexpr SizedEnum(Enum value) { *this = value; } |
| 17 | constexpr operator Enum() const { return static_cast<Enum>(mValue); } |
| 18 | constexpr SizedEnum& operator=(Enum value) |
| 19 | { |
| 20 | mValue = static_cast<Storage>(value); |
| 21 | return *this; |
| 22 | } |
| 23 | |
| 24 | Storage mValue; |
| 25 | }; |
| 26 | } // namespace sead |
| 27 | |