Add and use copy_const_t

This commit is contained in:
2025-05-14 00:23:11 +02:00
parent 088e03708a
commit f7a2699ac0
6 changed files with 22 additions and 10 deletions

View File

@ -146,6 +146,8 @@ struct _copy_const_helper<From, To, true> { using type = const To; };
template<typename From, typename To> using copy_cref_t = template<typename From, typename To> using copy_cref_t =
_copy_ref_helper<From, typename _copy_const_helper<From, un_cvref_t<To>>::type>::type; _copy_ref_helper<From, typename _copy_const_helper<From, un_cvref_t<To>>::type>::type;
template<typename From, typename To> using copy_const_t = _copy_const_helper<From, un_cvref_t<To>>::type;
template<typename T> struct _is_ptr_helper : false_type {}; template<typename T> struct _is_ptr_helper : false_type {};
template<typename T> struct _is_ptr_helper<T*> : true_type {}; template<typename T> struct _is_ptr_helper<T*> : true_type {};

View File

@ -274,6 +274,7 @@ static_assert(asl::same_or_derived_from<int, int>);
static_assert(!asl::is_const<int>); static_assert(!asl::is_const<int>);
static_assert(asl::is_const<const int>); static_assert(asl::is_const<const int>);
static_assert(!asl::is_const<const int*>); static_assert(!asl::is_const<const int*>);
static_assert(!asl::is_const<const int&>);
static_assert(asl::is_const<int* const>); static_assert(asl::is_const<int* const>);
static_assert(asl::is_floating_point<float>); static_assert(asl::is_floating_point<float>);
@ -362,6 +363,15 @@ static_assert(asl::same_as<asl::copy_cref_t<const int&, const float>, const floa
static_assert(asl::same_as<asl::copy_cref_t<const int&, float&&>, const float&>); static_assert(asl::same_as<asl::copy_cref_t<const int&, float&&>, const float&>);
static_assert(asl::same_as<asl::copy_cref_t<const int&, const float&>, const float&>); static_assert(asl::same_as<asl::copy_cref_t<const int&, const float&>, const float&>);
static_assert(asl::same_as<asl::copy_const_t<int, float>, float>);
static_assert(asl::same_as<asl::copy_const_t<int, const float>, float>);
static_assert(asl::same_as<asl::copy_const_t<const int, float>, const float>);
static_assert(asl::same_as<asl::copy_const_t<const int, const float>, const float>);
static_assert(asl::same_as<asl::copy_const_t<const int*, float>, float>);
static_assert(asl::same_as<asl::copy_const_t<int* const, float>, const float>);
static_assert(asl::same_as<asl::decay_t<int>, int>); static_assert(asl::same_as<asl::decay_t<int>, int>);
static_assert(!asl::same_as<asl::decay_t<int>, float>); static_assert(!asl::same_as<asl::decay_t<int>, float>);
static_assert(asl::same_as<asl::decay_t<int&>, int>); static_assert(asl::same_as<asl::decay_t<int&>, int>);

View File

@ -392,7 +392,7 @@ public:
auto data(this auto&& self) auto data(this auto&& self)
{ {
using return_type = un_ref_t<copy_cref_t<decltype(self), T>>*; using return_type = copy_const_t<un_ref_t<decltype(self)>, T>*;
// NOLINTNEXTLINE(*-reinterpret-cast) // NOLINTNEXTLINE(*-reinterpret-cast)
auto&& buffer = reinterpret_cast<copy_cref_t<decltype(self), class buffer>>(self); auto&& buffer = reinterpret_cast<copy_cref_t<decltype(self), class buffer>>(self);
if constexpr (kInlineCapacity == 0) if constexpr (kInlineCapacity == 0)
@ -410,13 +410,13 @@ public:
constexpr auto begin(this auto&& self) constexpr auto begin(this auto&& self)
{ {
using type = un_ref_t<copy_cref_t<decltype(self), T>>; using type = copy_const_t<un_ref_t<decltype(self)>, T>;
return contiguous_iterator<type>{self.data()}; return contiguous_iterator<type>{self.data()};
} }
constexpr auto end(this auto&& self) constexpr auto end(this auto&& self)
{ {
using type = un_ref_t<copy_cref_t<decltype(self), T>>; using type = copy_const_t<un_ref_t<decltype(self)>, T>;
return contiguous_iterator<type>{self.data() + self.size()}; return contiguous_iterator<type>{self.data() + self.size()};
} }
@ -432,7 +432,7 @@ public:
constexpr auto as_span(this auto&& self) constexpr auto as_span(this auto&& self)
{ {
using type = un_ref_t<copy_cref_t<decltype(self), T>>; using type = copy_const_t<un_ref_t<decltype(self)>, T>;
return span<type>{self.data(), self.size()}; return span<type>{self.data(), self.size()};
} }

View File

@ -147,7 +147,7 @@ public:
auto get(this auto&& self, const U& value) auto get(this auto&& self, const U& value)
requires key_hasher<KeyHasher, U> && key_comparator<KeyComparator, K, U> requires key_hasher<KeyHasher, U> && key_comparator<KeyComparator, K, U>
{ {
using return_type = un_ref_t<copy_cref_t<decltype(self), V>>*; using return_type = copy_const_t<un_ref_t<decltype(self)>, V>*;
isize_t index = self.find_slot_lookup(value); isize_t index = self.find_slot_lookup(value);
if (index >= 0) if (index >= 0)
{ {

View File

@ -82,13 +82,13 @@ public:
constexpr auto front(this auto&& self) constexpr auto front(this auto&& self)
{ {
using return_type = un_ref_t<copy_cref_t<decltype(self), T>>*; using return_type = copy_const_t<un_ref_t<decltype(self)>, T>*;
return return_type{ self.m_head }; return return_type{ self.m_head };
} }
constexpr auto back(this auto&& self) constexpr auto back(this auto&& self)
{ {
using return_type = un_ref_t<copy_cref_t<decltype(self), T>>*; using return_type = copy_const_t<un_ref_t<decltype(self)>, T>*;
return return_type{ self.m_head != nullptr ? self.m_head->m_prev : nullptr }; return return_type{ self.m_head != nullptr ? self.m_head->m_prev : nullptr };
} }

View File

@ -19,12 +19,12 @@ struct array
T m_data[kSize]; T m_data[kSize];
[[nodiscard]] constexpr bool is_empty() const { return false; } [[nodiscard]] constexpr bool is_empty() const { return false; }
[[nodiscard]] constexpr int64_t size() const { return kSize; } [[nodiscard]] constexpr int64_t size() const { return kSize; }
constexpr auto data(this auto&& self) constexpr auto data(this auto&& self)
{ {
using return_type = un_ref_t<copy_cref_t<decltype(self), T>>*; using return_type = copy_const_t<un_ref_t<decltype(self)>, T>*;
return static_cast<return_type>(self.m_data); return static_cast<return_type>(self.m_data);
} }
@ -54,7 +54,7 @@ struct array
constexpr auto as_span(this auto&& self) constexpr auto as_span(this auto&& self)
{ {
using type = un_ref_t<copy_cref_t<decltype(self), T>>; using type = copy_const_t<un_ref_t<decltype(self)>, T>;
return span<type, kSize>{self.data(), self.size()}; return span<type, kSize>{self.data(), self.size()};
} }