type_to_kind, type_list_and, type_list_or utils

This commit is contained in:
BlackMATov
2024-02-03 21:31:17 +07:00
parent c8a904a874
commit 65324af30b
3 changed files with 88 additions and 1 deletions

View File

@@ -46,4 +46,22 @@ TEST_CASE("meta/meta_base/type_list") {
static_assert(std::is_same_v<type_list_first_of_t<std::is_integral, long, type_list<float, double>>, long>);
}
SUBCASE("type_list_and_v") {
using meta::detail::type_list_and_v;
static_assert(type_list_and_v<std::is_integral, type_list<int, unsigned>>);
static_assert(!type_list_and_v<std::is_integral, type_list<float, unsigned>>);
static_assert(!type_list_and_v<std::is_integral, type_list<int, float>>);
static_assert(!type_list_and_v<std::is_integral, type_list<float, double>>);
}
SUBCASE("type_list_or_v") {
using meta::detail::type_list_or_v;
static_assert(type_list_or_v<std::is_integral, type_list<int, unsigned>>);
static_assert(type_list_or_v<std::is_integral, type_list<float, unsigned>>);
static_assert(type_list_or_v<std::is_integral, type_list<int, float>>);
static_assert(!type_list_or_v<std::is_integral, type_list<float, double>>);
}
}

View File

@@ -74,3 +74,48 @@ namespace meta_hpp::detail
template < typename T >
concept non_function_pointer_kind = std::is_pointer_v<T> && !std::is_function_v<std::remove_pointer_t<T>>;
}
namespace meta_hpp::detail
{
template < typename T >
struct type_to_kind;
template < typename T >
inline constexpr type_kind type_to_kind_v = type_to_kind<T>::value;
}
namespace meta_hpp::detail
{
template < array_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::array_> {};
template < class_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::class_> {};
template < enum_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::enum_> {};
template < function_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::function_> {};
template < member_pointer_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::member_> {};
template < method_pointer_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::method_> {};
template < nullptr_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::nullptr_> {};
template < number_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::number_> {};
template < pointer_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::pointer_> {};
template < reference_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::reference_> {};
template < void_kind T >
struct type_to_kind<T> : std::integral_constant<type_kind, type_kind::void_> {};
}

View File

@@ -14,7 +14,7 @@ namespace meta_hpp::detail
struct type_list {
template < typename F >
// NOLINTNEXTLINE(*-missing-std-forward)
static void for_each(F&& f) {
static constexpr void for_each(F&& f) {
(f.template operator()<Types>(), ...);
}
};
@@ -85,3 +85,27 @@ namespace meta_hpp::detail
template < template < typename > class Pred, typename Default, typename TypeList >
using type_list_first_of_t = typename type_list_first_of<Pred, Default, TypeList>::type;
}
namespace meta_hpp::detail
{
template < template < typename > class Pred, typename TypeList >
struct type_list_and;
template < template < typename > class Pred, typename... Types >
struct type_list_and<Pred, type_list<Types...>> : std::bool_constant<(... && Pred<Types>::value)> {};
template < template < typename > class Pred, typename TypeList >
inline constexpr bool type_list_and_v = type_list_and<Pred, TypeList>::value;
}
namespace meta_hpp::detail
{
template < template < typename > class Pred, typename TypeList >
struct type_list_or;
template < template < typename > class Pred, typename... Types >
struct type_list_or<Pred, type_list<Types...>> : std::bool_constant<(... || Pred<Types>::value)> {};
template < template < typename > class Pred, typename TypeList >
inline constexpr bool type_list_or_v = type_list_or<Pred, TypeList>::value;
}