diff --git a/parse/enum.hpp b/parse/enum.hpp index f0aea983..77d4e08a 100644 --- a/parse/enum.hpp +++ b/parse/enum.hpp @@ -18,6 +18,25 @@ namespace cruft::parse::enumeration { namespace detail { + /// Map a type to the underlying enum type if it is an enum, else + /// provided the identity mapping. Useful so simplify template logic + /// when dealing with types that aren't quite enums proper. + template + struct underlying_else_identity { using type = EnumT; }; + + + // Specialise for the enum case. + template + struct underlying_else_identity< + EnumT, + std::enable_if_t> + > { using type = std::underlying_type_t; }; + + + template + using underlying_else_identity_t = typename underlying_else_identity::type; + + /// Abstract base class for lookups from string names to typed /// integers. /// @@ -45,9 +64,7 @@ namespace cruft::parse::enumeration { /// specialised on the EnumT that the lookup is targetting. template struct lookup_concrete : public lookup_base { - static_assert (std::is_enum_v); - - using underlying_type = std::underlying_type_t; + using underlying_type = underlying_else_identity_t; using cache_type = std::map; lookup_concrete (cache_type _cache) @@ -101,21 +118,6 @@ namespace cruft::parse::enumeration { std::unique_ptr >& cache (void); - - - /// Map a type to the underlying enum type if it is an enum, else - /// provided the identity mapping. Useful so simplify template logic - /// when dealing with types that aren't quite enums proper. - template - struct underlying_else_identity { using type = EnumT; }; - - - // Specialise for the enum case. - template - struct underlying_else_identity< - EnumT, - std::enable_if_t> - > { using type = std::underlying_type_t; }; }; @@ -165,7 +167,7 @@ namespace cruft::parse::enumeration { sizeof (EnumT) == 8 ); - using underlying_type = typename detail::underlying_else_identity::type; + using underlying_type = detail::underlying_else_identity_t; static_assert (std::is_integral_v); if constexpr (std::is_signed_v) {