From 507a994399c9ddf7e78bd4a290e05f54ddc2f3a6 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 25 Feb 2025 22:46:15 +0100 Subject: Add copy_cref_t --- asl/base/meta.hpp | 22 +++++++++++++++++++++- asl/base/meta_tests.cpp | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'asl') diff --git a/asl/base/meta.hpp b/asl/base/meta.hpp index 17a7620..bbe5547 100644 --- a/asl/base/meta.hpp +++ b/asl/base/meta.hpp @@ -96,6 +96,8 @@ template struct _un_const_helper { using type = T; }; template using un_const_t = _un_const_helper::type; +template using as_const_t = const T; + template struct _is_const_helper : false_type {}; template struct _is_const_helper : true_type {}; @@ -108,7 +110,7 @@ template using un_volatile_t = _un_volatile_helper::type; template using un_cv_t = un_volatile_t>; -template using un_cvref_t = un_ref_t>; +template using un_cvref_t = un_cv_t>; template concept is_void = same_as>; @@ -120,6 +122,24 @@ template concept is_ref = _is_ref_helper::l || _is_ref_helper: template concept is_rref = _is_ref_helper::r; template concept is_lref = _is_ref_helper::l; +template, bool kRref = is_rref> +struct _copy_ref_helper { using type = To; }; + +template +struct _copy_ref_helper { using type = as_lref_t; }; + +template +struct _copy_ref_helper { using type = as_rref_t; }; + +template>> +struct _copy_const_helper { using type = To; }; + +template +struct _copy_const_helper { using type = const To; }; + +template using copy_cref_t = + _copy_ref_helper>::type>::type; + template struct _is_ptr_helper : false_type {}; template struct _is_ptr_helper : true_type {}; diff --git a/asl/base/meta_tests.cpp b/asl/base/meta_tests.cpp index 7aa7145..99cc6c0 100644 --- a/asl/base/meta_tests.cpp +++ b/asl/base/meta_tests.cpp @@ -287,3 +287,23 @@ ASL_TEST(deref) wants_base_ptr(&asl::deref(d)); } +static_assert(asl::same_as, float>); +static_assert(asl::same_as, float>); +static_assert(asl::same_as, float>); +static_assert(asl::same_as, float>); + +static_assert(asl::same_as, float&&>); +static_assert(asl::same_as, float&&>); +static_assert(asl::same_as, float&&>); +static_assert(asl::same_as, float&&>); + +static_assert(asl::same_as, const float>); +static_assert(asl::same_as, const float>); +static_assert(asl::same_as, const float>); +static_assert(asl::same_as, const float>); + +static_assert(asl::same_as, const float&>); +static_assert(asl::same_as, const float&>); +static_assert(asl::same_as, const float&>); +static_assert(asl::same_as, const float&>); + -- cgit