Skip to content

Commit ec147d5

Browse files
committed
✨ Add is_scoped_enum
Problem: - `is_scoped_enum_v` is fine, but a type is also needed for use in the `has_trait` concept. Solution: - Add `is_scoped_enum`.
1 parent 7cdfadd commit ec147d5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/stdx/type_traits.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ constexpr auto is_specialization_of()
114114

115115
template <typename E>
116116
constexpr bool is_scoped_enum_v =
117-
std::is_enum_v<E> and
118-
not std::is_convertible_v<E, std::underlying_type_t<E>>;
117+
std::is_enum_v<E> and not std::is_convertible_v<E, underlying_type_t<E>>;
118+
template <typename E>
119+
using is_scoped_enum = std::bool_constant<is_scoped_enum_v<E>>;
119120

120121
template <typename...> struct type_list {};
121122
template <auto...> struct value_list {};

test/type_traits.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,13 @@ enum struct E2 {};
7777
} // namespace
7878

7979
TEST_CASE("is_scoped_enum", "[type_traits]") {
80+
static_assert(not stdx::is_scoped_enum_v<int>);
8081
static_assert(not stdx::is_scoped_enum_v<E1>);
8182
static_assert(stdx::is_scoped_enum_v<E2>);
83+
84+
static_assert(not stdx::is_scoped_enum<int>::value);
85+
static_assert(not stdx::is_scoped_enum<E1>::value);
86+
static_assert(stdx::is_scoped_enum<E2>::value);
8287
}
8388

8489
TEST_CASE("type_identity", "[type_traits]") {

0 commit comments

Comments
 (0)