Skip to content

Commit 774fd51

Browse files
committed
Implement is_any_of using fold expression
1 parent b9cf8a7 commit 774fd51

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

include/nbl/type_traits.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@ using bool_constant = std::bool_constant<B>;
1818
template <bool... Vals>
1919
using bool_sequence = std::integer_sequence<bool, Vals...>;
2020

21-
22-
template<typename T, typename U, typename... Us>
23-
struct NBL_API is_any_of : std::integral_constant<bool,
24-
std::conditional<
25-
std::is_same<T, U>::value,
26-
std::true_type,
27-
nbl::is_any_of<T, Us...>
28-
>::type::value
29-
>
30-
{};
31-
32-
template<typename T, typename U>
33-
struct NBL_API is_any_of<T, U> : std::is_same<T, U>::type { };
34-
21+
template <typename T, typename... Us>
22+
_INLINE_VAR constexpr bool is_any_of_v = (... || std::is_same<T, Us>::value);
23+
24+
template<typename T, typename... Us>
25+
struct NBL_API is_any_of : std::integral_constant<bool, is_any_of_v<T, Us...>> {};
26+
27+
static_assert(is_any_of<bool, bool>::value == true, "is_any_of test");
28+
static_assert(is_any_of<bool, int>::value == false, "is_any_of test");
29+
static_assert(is_any_of<bool, int, bool>::value == true, "is_any_of test");
30+
static_assert(is_any_of<bool, int, double>::value == false, "is_any_of test");
31+
static_assert(is_any_of<bool, int, double, bool>::value == true, "is_any_of test");
32+
static_assert(is_any_of<bool, int, double, float>::value == false, "is_any_of test");
3533

3634
template<auto cf, decltype(cf) cmp, decltype(cf)... searchtab>
3735
struct NBL_API is_any_of_values : is_any_of_values<cf,searchtab...> {};

0 commit comments

Comments
 (0)