From f7a2699ac0cbb2824862439a72f23013436484de Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 14 May 2025 00:23:11 +0200 Subject: Add and use copy_const_t --- asl/base/meta.hpp | 2 ++ asl/base/meta_tests.cpp | 10 ++++++++++ asl/containers/buffer.hpp | 8 ++++---- asl/containers/hash_map.hpp | 2 +- asl/containers/intrusive_list.hpp | 4 ++-- asl/types/array.hpp | 6 +++--- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/asl/base/meta.hpp b/asl/base/meta.hpp index 3675df3..e050e69 100644 --- a/asl/base/meta.hpp +++ b/asl/base/meta.hpp @@ -146,6 +146,8 @@ struct _copy_const_helper { using type = const To; }; template using copy_cref_t = _copy_ref_helper>::type>::type; +template using copy_const_t = _copy_const_helper>::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 7bae295..36b0429 100644 --- a/asl/base/meta_tests.cpp +++ b/asl/base/meta_tests.cpp @@ -274,6 +274,7 @@ static_assert(asl::same_or_derived_from); static_assert(!asl::is_const); static_assert(asl::is_const); static_assert(!asl::is_const); +static_assert(!asl::is_const); static_assert(asl::is_const); static_assert(asl::is_floating_point); @@ -362,6 +363,15 @@ 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, 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, 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>); diff --git a/asl/containers/buffer.hpp b/asl/containers/buffer.hpp index d61abf9..0e30745 100644 --- a/asl/containers/buffer.hpp +++ b/asl/containers/buffer.hpp @@ -392,7 +392,7 @@ public: auto data(this auto&& self) { - using return_type = un_ref_t>*; + using return_type = copy_const_t, T>*; // NOLINTNEXTLINE(*-reinterpret-cast) auto&& buffer = reinterpret_cast>(self); if constexpr (kInlineCapacity == 0) @@ -410,13 +410,13 @@ public: constexpr auto begin(this auto&& self) { - using type = un_ref_t>; + using type = copy_const_t, T>; return contiguous_iterator{self.data()}; } constexpr auto end(this auto&& self) { - using type = un_ref_t>; + using type = copy_const_t, T>; return contiguous_iterator{self.data() + self.size()}; } @@ -432,7 +432,7 @@ public: constexpr auto as_span(this auto&& self) { - using type = un_ref_t>; + using type = copy_const_t, T>; return span{self.data(), self.size()}; } diff --git a/asl/containers/hash_map.hpp b/asl/containers/hash_map.hpp index dc140eb..a6d72dd 100644 --- a/asl/containers/hash_map.hpp +++ b/asl/containers/hash_map.hpp @@ -147,7 +147,7 @@ public: auto get(this auto&& self, const U& value) requires key_hasher && key_comparator { - using return_type = un_ref_t>*; + using return_type = copy_const_t, V>*; isize_t index = self.find_slot_lookup(value); if (index >= 0) { diff --git a/asl/containers/intrusive_list.hpp b/asl/containers/intrusive_list.hpp index 81816ec..5ce69aa 100644 --- a/asl/containers/intrusive_list.hpp +++ b/asl/containers/intrusive_list.hpp @@ -82,13 +82,13 @@ public: constexpr auto front(this auto&& self) { - using return_type = un_ref_t>*; + using return_type = copy_const_t, T>*; return return_type{ self.m_head }; } constexpr auto back(this auto&& self) { - using return_type = un_ref_t>*; + using return_type = copy_const_t, T>*; return return_type{ self.m_head != nullptr ? self.m_head->m_prev : nullptr }; } diff --git a/asl/types/array.hpp b/asl/types/array.hpp index 5fb300a..54c3fbe 100644 --- a/asl/types/array.hpp +++ b/asl/types/array.hpp @@ -19,12 +19,12 @@ struct array T m_data[kSize]; [[nodiscard]] constexpr bool is_empty() const { return false; } - + [[nodiscard]] constexpr int64_t size() const { return kSize; } constexpr auto data(this auto&& self) { - using return_type = un_ref_t>*; + using return_type = copy_const_t, T>*; return static_cast(self.m_data); } @@ -54,7 +54,7 @@ struct array constexpr auto as_span(this auto&& self) { - using type = un_ref_t>; + using type = copy_const_t, T>; return span{self.data(), self.size()}; } -- cgit