diff --git a/include/asenum/asenum.h b/include/asenum/asenum.h index 04d351f..48d74cb 100644 --- a/include/asenum/asenum.h +++ b/include/asenum/asenum.h @@ -146,7 +146,10 @@ private: \ \ public: \ template \ - static ThisType create(typename CaseCast::Type value) \ + using UnderlyingType = typename CaseCast::Type; \ + \ + template \ + static ThisType create(UnderlyingType value) \ { \ return ThisType(T_type, std::move(value)); \ } \ @@ -158,7 +161,7 @@ public: \ } \ \ template \ - const typename CaseCast::Type& as() const \ + const UnderlyingType& as() const \ { \ return validatedValueOfType::Type>(T_type); \ } \ diff --git a/tests/AsEnumTest.cpp b/tests/AsEnumTest.cpp index 1f979b4..de73438 100644 --- a/tests/AsEnumTest.cpp +++ b/tests/AsEnumTest.cpp @@ -47,6 +47,10 @@ namespace ASENUM_CASE(StringOpt, std::string); ASENUM_CASE(BoolOpt, bool); }; + + static_assert(std::is_same, int>::value, "Invalid underlying type"); + static_assert(std::is_same, std::string>::value, "Invalid underlying type"); + static_assert(std::is_same, bool>::value, "Invalid underlying type"); } TEST(AsEnum, NamedGetter)