mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
fix uvalue copy traits
ref: https://github.com/BlackMATov/meta.hpp/issues/100
This commit is contained in:
@@ -22,10 +22,89 @@ namespace meta_hpp::detail
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
requires requires(const T& v) { uvalue{v}; }
|
||||
requires(!std::is_class_v<T> && std::is_copy_constructible_v<T>)
|
||||
struct copy_traits<T> {
|
||||
uvalue operator()(const T& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
requires has_copy_traits<T>
|
||||
struct copy_traits<std::array<T, Size>> {
|
||||
using value_t = std::array<T, Size>;
|
||||
|
||||
uvalue operator()(const value_t& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T, typename Traits, typename Allocator >
|
||||
requires has_copy_traits<T>
|
||||
struct copy_traits<std::basic_string<T, Traits, Allocator>> {
|
||||
using value_t = std::basic_string<T, Traits, Allocator>;
|
||||
|
||||
uvalue operator()(const value_t& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T, typename Traits >
|
||||
requires has_copy_traits<T>
|
||||
struct copy_traits<std::basic_string_view<T, Traits>> {
|
||||
using value_t = std::basic_string_view<T, Traits>;
|
||||
|
||||
uvalue operator()(const value_t& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T, typename Allocator >
|
||||
requires has_copy_traits<T>
|
||||
struct copy_traits<std::vector<T, Allocator>> {
|
||||
using value_t = std::vector<T, Allocator>;
|
||||
|
||||
uvalue operator()(const value_t& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct copy_traits<std::shared_ptr<T>> {
|
||||
using value_t = std::shared_ptr<T>;
|
||||
|
||||
uvalue operator()(const value_t& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct copy_traits<std::reference_wrapper<T>> {
|
||||
using value_t = std::reference_wrapper<T>;
|
||||
|
||||
uvalue operator()(const value_t& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
|
||||
template < typename... Ts >
|
||||
requires(... && has_copy_traits<Ts>)
|
||||
struct copy_traits<std::tuple<Ts...>> {
|
||||
using value_t = std::tuple<Ts...>;
|
||||
|
||||
uvalue operator()(const value_t& v) const {
|
||||
return uvalue{v};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#define META_HPP_DECLARE_COPY_TRAITS_FOR(T) \
|
||||
namespace meta_hpp::detail \
|
||||
{ \
|
||||
template <> \
|
||||
struct copy_traits<T> { \
|
||||
uvalue operator()(const T& v) const { \
|
||||
return uvalue{v}; \
|
||||
} \
|
||||
}; \
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user