From 7d1cf96938808cb9a6161fc4d44d63ad8aacf8ee Mon Sep 17 00:00:00 2001 From: "Alkenso (Vladimir Vashurkin)" Date: Sun, 28 Jul 2019 11:49:14 +0300 Subject: [PATCH] Added alias for UnderlyingType --- include/asenum/asenum.h | 7 +++++-- tests/AsEnumTest.cpp | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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)