From a665c590d5089bb4bcb72193542b60ef571409a3 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 20 Mar 2025 19:28:56 +0100 Subject: Add decay --- asl/base/meta.hpp | 25 +++++++++++++++++++++---- asl/base/meta_tests.cpp | 14 ++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/asl/base/meta.hpp b/asl/base/meta.hpp index 8bebf2f..93e5603 100644 --- a/asl/base/meta.hpp +++ b/asl/base/meta.hpp @@ -54,6 +54,11 @@ template using as_rref_t = decltype(_as_rref_helper(0))::type; template consteval as_rref_t declval() {} +template auto _as_ptr_helper(int) -> id; +template auto _as_ptr_helper(...) -> id; + +template using as_ptr_t = decltype(_as_ptr_helper(0))::type; + template struct _un_ref_t { using type = T; }; template struct _un_ref_t { using type = T; }; template struct _un_ref_t { using type = T; }; @@ -191,11 +196,23 @@ template concept is_func = _is_func_helper>::value; template concept is_object = !is_void && !is_ref && !is_func; -template struct _is_array_helper : false_type {}; -template struct _is_array_helper : true_type {}; -template struct _is_array_helper : true_type {}; +template struct _array_helper : false_type { using type = T; }; +template struct _array_helper : true_type { using type = T; }; +template struct _array_helper : true_type { using type = T; }; + +template concept is_array = _array_helper::value; -template concept is_array = _is_array_helper::value; +template using remove_extent_t = _array_helper::type; + +template +using decay_t = + select_t< + is_array>, + as_ptr_t>>, + select_t< + is_func>, + as_ptr_t>, + un_cv_t>>>; template struct _is_floating_point_helper : false_type {}; template<> struct _is_floating_point_helper : true_type {}; diff --git a/asl/base/meta_tests.cpp b/asl/base/meta_tests.cpp index 490b453..bcd9775 100644 --- a/asl/base/meta_tests.cpp +++ b/asl/base/meta_tests.cpp @@ -189,6 +189,10 @@ static_assert(!asl::is_array); static_assert(!asl::is_array); static_assert(!asl::is_array); +static_assert(asl::same_as>); +static_assert(asl::same_as>); +static_assert(asl::same_as>); + static_assert(asl::same_as>); static_assert(asl::same_as>); static_assert(asl::same_as>); @@ -318,3 +322,13 @@ static_assert(asl::same_as, const floa static_assert(asl::same_as, const float&>); static_assert(asl::same_as, const float&>); +static_assert(asl::same_as, int>); +static_assert(!asl::same_as, float>); +static_assert(asl::same_as, int>); +static_assert(asl::same_as, int>); +static_assert(asl::same_as, int>); +static_assert(asl::same_as, int*>); +static_assert(!asl::same_as, int*>); +static_assert(!asl::same_as, int**>); +static_assert(asl::same_as, int(*)[2]>); +static_assert(asl::same_as, int(*)(int)>); -- cgit