rewrite uvalue traits

This commit is contained in:
BlackMATov
2023-12-30 12:32:22 +07:00
parent e25af84b3f
commit 50d6ab4974
8 changed files with 21 additions and 158 deletions

View File

@@ -15,7 +15,7 @@
#include <algorithm>
#include <array>
#include <compare>
#include <deque>
#include <concepts>
#include <exception>
#include <functional>
#include <initializer_list>

View File

@@ -24,7 +24,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < typename T >
requires std::is_copy_constructible_v<T>
requires requires(const T& v) { uvalue{v}; }
struct copy_traits<T> {
uvalue operator()(const T& v) const {
return uvalue{v};

View File

@@ -24,26 +24,10 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < typename T >
requires std::is_copy_constructible_v<T>
struct deref_traits<T*> {
uvalue operator()(T* v) const {
return v != nullptr ? uvalue{*v} : uvalue{};
}
};
template < typename T >
requires std::is_copy_constructible_v<T>
struct deref_traits<std::shared_ptr<T>> {
uvalue operator()(const std::shared_ptr<T>& v) const {
return v != nullptr ? uvalue{*v} : uvalue{};
}
};
template < typename T >
requires std::is_copy_constructible_v<T>
struct deref_traits<std::unique_ptr<T>> {
uvalue operator()(const std::unique_ptr<T>& v) const {
return v != nullptr ? uvalue{*v} : uvalue{};
requires requires(const T& v) { uvalue{*v}; }
struct deref_traits<T> {
uvalue operator()(const T& v) const {
return uvalue{*v};
}
};
}

View File

@@ -24,51 +24,10 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < typename T >
requires std::is_copy_constructible_v<T>
struct index_traits<T*> {
uvalue operator()(T* v, std::size_t i) const {
// NOLINTNEXTLINE(*-pointer-arithmetic)
return v != nullptr ? uvalue{v[i]} : uvalue{};
}
};
template < typename T, std::size_t Size >
requires std::is_copy_constructible_v<T>
struct index_traits<std::array<T, Size>> {
uvalue operator()(const std::array<T, Size>& v, std::size_t i) const {
return i < v.size() ? uvalue{v[i]} : uvalue{};
}
};
template < typename T, typename Allocator >
requires std::is_copy_constructible_v<T>
struct index_traits<std::deque<T, Allocator>> {
uvalue operator()(const std::deque<T, Allocator>& v, std::size_t i) {
return i < v.size() ? uvalue{v[i]} : uvalue{};
}
};
template < typename T, std::size_t Extent >
requires std::is_copy_constructible_v<T>
struct index_traits<std::span<T, Extent>> {
uvalue operator()(const std::span<T, Extent>& v, std::size_t i) const {
return i < v.size() ? uvalue{v[i]} : uvalue{};
}
};
template < typename T, typename Traits, typename Allocator >
requires std::is_copy_constructible_v<T>
struct index_traits<std::basic_string<T, Traits, Allocator>> {
uvalue operator()(const std::basic_string<T, Traits, Allocator>& v, std::size_t i) const {
return i < v.size() ? uvalue{v[i]} : uvalue{};
}
};
template < typename T, typename Allocator >
requires std::is_copy_constructible_v<T>
struct index_traits<std::vector<T, Allocator>> {
uvalue operator()(const std::vector<T, Allocator>& v, std::size_t i) {
return i < v.size() ? uvalue{v[i]} : uvalue{};
requires requires(const T& v, std::size_t i) { uvalue{v[i]}; }
struct index_traits<T> {
uvalue operator()(const T& v, std::size_t i) const {
return uvalue{v[i]};
}
};
}