mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-13 19:18:01 +07:00
rewrite uvalue traits
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <compare>
|
||||
#include <deque>
|
||||
#include <concepts>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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]};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user