Skip to content

Commit

Permalink
Added alias for UnderlyingType
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkenso committed Jul 28, 2019
1 parent 7940272 commit 7d1cf96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/asenum/asenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ private: \
\
public: \
template <AssociatedEnum T_type> \
static ThisType create(typename CaseCast<T_type>::Type value) \
using UnderlyingType = typename CaseCast<T_type>::Type; \
\
template <AssociatedEnum T_type> \
static ThisType create(UnderlyingType<T_type> value) \
{ \
return ThisType(T_type, std::move(value)); \
} \
Expand All @@ -158,7 +161,7 @@ public: \
} \
\
template <AssociatedEnum T_type> \
const typename CaseCast<T_type>::Type& as() const \
const UnderlyingType<T_type>& as() const \
{ \
return validatedValueOfType<typename CaseCast<T_type>::Type>(T_type); \
} \
Expand Down
4 changes: 4 additions & 0 deletions tests/AsEnumTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ namespace
ASENUM_CASE(StringOpt, std::string);
ASENUM_CASE(BoolOpt, bool);
};

static_assert(std::is_same<TestAsEnum::UnderlyingType<TestEnum::Unknown>, int>::value, "Invalid underlying type");
static_assert(std::is_same<TestAsEnum::UnderlyingType<TestEnum::StringOpt>, std::string>::value, "Invalid underlying type");
static_assert(std::is_same<TestAsEnum::UnderlyingType<TestEnum::BoolOpt>, bool>::value, "Invalid underlying type");
}

TEST(AsEnum, NamedGetter)
Expand Down

0 comments on commit 7d1cf96

Please sign in to comment.