From add3e12550d03d4408dc4e3169e55c8415e250a9 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 20 Aug 2024 10:13:08 +0200 Subject: Rewrite the 4 categories --- asl/meta.hpp | 155 ++++++++++++++++++++--------------------------------------- 1 file changed, 51 insertions(+), 104 deletions(-) (limited to 'asl/meta.hpp') diff --git a/asl/meta.hpp b/asl/meta.hpp index 4a5b448..be5fa50 100644 --- a/asl/meta.hpp +++ b/asl/meta.hpp @@ -15,6 +15,11 @@ template struct _select_helper template using select_t = _select_helper::type; +template struct _is_same_helper : false_type {}; +template struct _is_same_helper : true_type {}; + +template concept is_same = _is_same_helper::value && _is_same_helper::value; + template auto _as_lref_helper(int) -> id; template auto _as_lref_helper(...) -> id; @@ -50,124 +55,66 @@ template concept trivially_destructible = __is_trivially_destructibl using nullptr_t = decltype(nullptr); -template struct un_ref { using type = T; }; -template struct un_ref { using type = T; }; -template struct un_ref { using type = T; }; -template using un_ref_t = un_ref::type; - -template struct un_const { using type = T; }; -template struct un_const { using type = T; }; -template using un_const_t = un_const::type; - -template struct un_volatile { using type = T; }; -template struct un_volatile { using type = T; }; -template using un_volatile_t = un_volatile::type; - -template using un_qual_t = un_const_t>; - -template using un_qualref_t = un_qual_t>; - -template struct _is_same_helper : false_type {}; -template struct _is_same_helper : true_type {}; - -template -concept is_same = _is_same_helper::value && _is_same_helper::value; - -template struct _is_const_helper : false_type {}; -template struct _is_const_helper : true_type {}; - -template concept is_const = _is_const_helper::value; +template struct _un_const_helper { using type = T; }; +template struct _un_const_helper { using type = T; }; -template concept is_void = is_same, void>; -template concept is_nullptr = is_same, nullptr_t>; +template using un_const_t = _un_const_helper::type; -template concept is_integral = __is_integral(T); -template concept is_floating_point = __is_floating_point(T); -template concept is_arithmetic = is_integral || is_floating_point; +template struct _un_volatile_helper { using type = T; }; +template struct _un_volatile_helper { using type = T; }; -template struct _is_array_helper : false_type {}; -template struct _is_array_helper : true_type {}; -template struct _is_array_helper : true_type {}; +template using un_volatile_t = _un_volatile_helper::type; -template concept is_array = _is_array_helper::value; +template using un_cv_t = un_volatile_t>; -template concept is_class = __is_class(T); -template concept is_union = __is_union(T); +template concept is_void = is_same>; -template concept is_enum = __is_enum(T); +template struct _is_ref_helper { static constexpr bool l = false; static constexpr bool r = false; }; +template struct _is_ref_helper { static constexpr bool l = true; static constexpr bool r = false; }; +template struct _is_ref_helper { static constexpr bool l = false; static constexpr bool r = true; }; -template struct _is_ptr_helper : false_type {}; -template struct _is_ptr_helper : true_type {}; +template concept is_ref = _is_ref_helper::l || _is_ref_helper::r; -template concept is_ptr = _is_ptr_helper>::value; +template struct _tame_helper { using type = T; }; -template struct _is_ref_helper { static constexpr bool lref = false; static constexpr bool rref = false; }; -template struct _is_ref_helper { static constexpr bool lref = true; static constexpr bool rref = false; }; -template struct _is_ref_helper { static constexpr bool lref = false; static constexpr bool rref = true; }; +#define TAME_HELPER_IMPL(TRAILING) \ + template \ + struct _tame_helper { using type = R(Args...); } -template concept is_lref = _is_ref_helper::lref; -template concept is_rref = _is_ref_helper::rref; -template concept is_ref = is_lref || is_rref; +TAME_HELPER_IMPL(); +TAME_HELPER_IMPL(&); +TAME_HELPER_IMPL(&&); +TAME_HELPER_IMPL(const); +TAME_HELPER_IMPL(const &); +TAME_HELPER_IMPL(const &&); +TAME_HELPER_IMPL(volatile); +TAME_HELPER_IMPL(volatile &); +TAME_HELPER_IMPL(volatile &&); +TAME_HELPER_IMPL(const volatile); +TAME_HELPER_IMPL(const volatile &); +TAME_HELPER_IMPL(const volatile &&); +TAME_HELPER_IMPL(noexcept); +TAME_HELPER_IMPL(& noexcept); +TAME_HELPER_IMPL(&& noexcept); +TAME_HELPER_IMPL(const noexcept); +TAME_HELPER_IMPL(const & noexcept); +TAME_HELPER_IMPL(const && noexcept); +TAME_HELPER_IMPL(volatile noexcept); +TAME_HELPER_IMPL(volatile & noexcept); +TAME_HELPER_IMPL(volatile && noexcept); +TAME_HELPER_IMPL(const volatile noexcept); +TAME_HELPER_IMPL(const volatile & noexcept); +TAME_HELPER_IMPL(const volatile && noexcept); -template concept is_func = !is_const && !is_ref; - -template struct _is_member_ptr_helper : false_type {}; -template struct _is_member_ptr_helper : true_type {}; - -template struct _is_member_func_ptr_helper : false_type {}; -template struct _is_member_func_ptr_helper : bool_constant> {}; - -template concept is_member_ptr = _is_member_ptr_helper>::value; -template concept is_member_func_ptr = _is_member_func_ptr_helper>::value; -template concept is_member_object_ptr = is_member_ptr && !is_member_func_ptr; - -template concept is_fundamental = is_arithmetic || is_void || is_nullptr; -template concept is_compound = !is_fundamental; -template concept is_scalar = (is_fundamental && !is_void) || is_enum || is_ptr || is_member_ptr; -template concept is_object = is_scalar || is_class || is_union; - -template concept is_empty = is_void || __is_empty(T); - -struct empty {}; - -template using devoid_t = select_t, empty, T>; - -template struct _tame_helper { using type = F; }; - -#define ASL_TAME_IMPL(SUFFIX) \ - template \ - struct _tame_helper { using type = Ret(Args...); } - -ASL_TAME_IMPL(); -ASL_TAME_IMPL(const); -ASL_TAME_IMPL(volatile); -ASL_TAME_IMPL(volatile const); -ASL_TAME_IMPL(&&); -ASL_TAME_IMPL(const &&); -ASL_TAME_IMPL(volatile &&); -ASL_TAME_IMPL(volatile const &&); -ASL_TAME_IMPL(&); -ASL_TAME_IMPL(const &); -ASL_TAME_IMPL(volatile &); -ASL_TAME_IMPL(volatile const &); -ASL_TAME_IMPL(noexcept); -ASL_TAME_IMPL(const noexcept); -ASL_TAME_IMPL(volatile noexcept); -ASL_TAME_IMPL(volatile const noexcept); -ASL_TAME_IMPL(&& noexcept); -ASL_TAME_IMPL(const && noexcept); -ASL_TAME_IMPL(volatile && noexcept); -ASL_TAME_IMPL(volatile const && noexcept); -ASL_TAME_IMPL(& noexcept); -ASL_TAME_IMPL(const & noexcept); -ASL_TAME_IMPL(volatile & noexcept); -ASL_TAME_IMPL(volatile const & noexcept); - -#undef ASL_TAME_IMPL +#undef TAME_HELPER_IMPL template using tame_t = _tame_helper::type; -template using as_raw_ptr_t = un_ref_t>*; +template struct _is_func_helper : false_type {}; +template struct _is_func_helper : true_type {}; + +template concept is_func = _is_func_helper>::value; +template concept is_object = !is_void && !is_ref && !is_func; } // namespace asl -- cgit