mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
rewrite uvalue traits
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
- fix all includes to work with the library more flexible
|
- fix all includes to work with the library more flexible
|
||||||
- test and support shared libraries
|
- test and support shared libraries
|
||||||
- add debug type names
|
- add debug type names
|
||||||
- auto register destructor without class_<T>
|
|
||||||
|
|
||||||
## Version 1.0
|
## Version 1.0
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,11 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <compare>
|
#include <compare>
|
||||||
|
#include <concepts>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <deque>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
@@ -8991,7 +8991,7 @@ namespace meta_hpp::detail
|
|||||||
namespace meta_hpp::detail
|
namespace meta_hpp::detail
|
||||||
{
|
{
|
||||||
template < typename T >
|
template < typename T >
|
||||||
requires std::is_copy_constructible_v<T>
|
requires requires(const T& v) { uvalue{v}; }
|
||||||
struct copy_traits<T> {
|
struct copy_traits<T> {
|
||||||
uvalue operator()(const T& v) const {
|
uvalue operator()(const T& v) const {
|
||||||
return uvalue{v};
|
return uvalue{v};
|
||||||
@@ -9014,26 +9014,10 @@ namespace meta_hpp::detail
|
|||||||
namespace meta_hpp::detail
|
namespace meta_hpp::detail
|
||||||
{
|
{
|
||||||
template < typename T >
|
template < typename T >
|
||||||
requires std::is_copy_constructible_v<T>
|
requires requires(const T& v) { uvalue{*v}; }
|
||||||
struct deref_traits<T*> {
|
struct deref_traits<T> {
|
||||||
uvalue operator()(T* v) const {
|
uvalue operator()(const T& v) const {
|
||||||
return v != nullptr ? uvalue{*v} : uvalue{};
|
return uvalue{*v};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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{};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -9053,51 +9037,10 @@ namespace meta_hpp::detail
|
|||||||
namespace meta_hpp::detail
|
namespace meta_hpp::detail
|
||||||
{
|
{
|
||||||
template < typename T >
|
template < typename T >
|
||||||
requires std::is_copy_constructible_v<T>
|
requires requires(const T& v, std::size_t i) { uvalue{v[i]}; }
|
||||||
struct index_traits<T*> {
|
struct index_traits<T> {
|
||||||
uvalue operator()(T* v, std::size_t i) const {
|
uvalue operator()(const T& v, std::size_t i) const {
|
||||||
// NOLINTNEXTLINE(*-pointer-arithmetic)
|
return uvalue{v[i]};
|
||||||
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{};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ TEST_CASE("meta/meta_issues/random/3") {
|
|||||||
|
|
||||||
{
|
{
|
||||||
meta::uvalue v{&int_func};
|
meta::uvalue v{&int_func};
|
||||||
CHECK_FALSE(v.has_deref_op());
|
CHECK(v.has_deref_op());
|
||||||
CHECK(v.get_type() == meta::resolve_type<int(*)()>());
|
CHECK(v.get_type() == meta::resolve_type<int(*)()>());
|
||||||
CHECK((v.as<decltype(&int_func)>() == &int_func));
|
CHECK((v.as<decltype(&int_func)>() == &int_func));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -584,9 +584,6 @@ TEST_CASE("meta/meta_utilities/value") {
|
|||||||
|
|
||||||
CHECK(meta::uvalue{p1}.has_deref_op());
|
CHECK(meta::uvalue{p1}.has_deref_op());
|
||||||
CHECK(meta::uvalue{p2}.has_deref_op());
|
CHECK(meta::uvalue{p2}.has_deref_op());
|
||||||
|
|
||||||
CHECK_FALSE(*meta::uvalue{p1});
|
|
||||||
CHECK_FALSE(*meta::uvalue{p2});
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ivec2 v{1,2};
|
ivec2 v{1,2};
|
||||||
@@ -657,8 +654,6 @@ TEST_CASE("meta/meta_utilities/value/arrays") {
|
|||||||
meta::uvalue v{arr};
|
meta::uvalue v{arr};
|
||||||
CHECK(v.get_type() == meta::resolve_type<int*>());
|
CHECK(v.get_type() == meta::resolve_type<int*>());
|
||||||
CHECK(v.has_index_op());
|
CHECK(v.has_index_op());
|
||||||
|
|
||||||
CHECK_FALSE(v[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,8 +673,6 @@ TEST_CASE("meta/meta_utilities/value/arrays") {
|
|||||||
meta::uvalue v{arr};
|
meta::uvalue v{arr};
|
||||||
CHECK(v.get_type() == meta::resolve_type<const int*>());
|
CHECK(v.get_type() == meta::resolve_type<const int*>());
|
||||||
CHECK(v.has_index_op());
|
CHECK(v.has_index_op());
|
||||||
|
|
||||||
CHECK_FALSE(v[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,18 +684,6 @@ TEST_CASE("meta/meta_utilities/value/arrays") {
|
|||||||
CHECK(v[0].as<int>() == 1);
|
CHECK(v[0].as<int>() == 1);
|
||||||
CHECK(v[1].as<int>() == 2);
|
CHECK(v[1].as<int>() == 2);
|
||||||
CHECK(v[2].as<int>() == 3);
|
CHECK(v[2].as<int>() == 3);
|
||||||
CHECK_FALSE(v[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SUBCASE("std::deque") {
|
|
||||||
const meta::uvalue v{std::deque{1,2,3}};
|
|
||||||
CHECK(v.get_type() == meta::resolve_type<std::deque<int>>());
|
|
||||||
CHECK(v.has_index_op());
|
|
||||||
|
|
||||||
CHECK(v[0].as<int>() == 1);
|
|
||||||
CHECK(v[1].as<int>() == 2);
|
|
||||||
CHECK(v[2].as<int>() == 3);
|
|
||||||
CHECK_FALSE(v[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("std::string") {
|
SUBCASE("std::string") {
|
||||||
@@ -713,7 +694,6 @@ TEST_CASE("meta/meta_utilities/value/arrays") {
|
|||||||
CHECK(v[0].as<char>() == 'h');
|
CHECK(v[0].as<char>() == 'h');
|
||||||
CHECK(v[1].as<char>() == 'i');
|
CHECK(v[1].as<char>() == 'i');
|
||||||
CHECK(v[2].as<char>() == '!');
|
CHECK(v[2].as<char>() == '!');
|
||||||
CHECK_FALSE(v[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("std::span") {
|
SUBCASE("std::span") {
|
||||||
@@ -725,7 +705,6 @@ TEST_CASE("meta/meta_utilities/value/arrays") {
|
|||||||
CHECK(v[0].as<int>() == 1);
|
CHECK(v[0].as<int>() == 1);
|
||||||
CHECK(v[1].as<int>() == 2);
|
CHECK(v[1].as<int>() == 2);
|
||||||
CHECK(v[2].as<int>() == 3);
|
CHECK(v[2].as<int>() == 3);
|
||||||
CHECK_FALSE(v[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("std::vector") {
|
SUBCASE("std::vector") {
|
||||||
@@ -736,7 +715,6 @@ TEST_CASE("meta/meta_utilities/value/arrays") {
|
|||||||
CHECK(v[0].as<int>() == 1);
|
CHECK(v[0].as<int>() == 1);
|
||||||
CHECK(v[1].as<int>() == 2);
|
CHECK(v[1].as<int>() == 2);
|
||||||
CHECK(v[2].as<int>() == 3);
|
CHECK(v[2].as<int>() == 3);
|
||||||
CHECK_FALSE(v[3]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <compare>
|
#include <compare>
|
||||||
#include <deque>
|
#include <concepts>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace meta_hpp::detail
|
|||||||
namespace meta_hpp::detail
|
namespace meta_hpp::detail
|
||||||
{
|
{
|
||||||
template < typename T >
|
template < typename T >
|
||||||
requires std::is_copy_constructible_v<T>
|
requires requires(const T& v) { uvalue{v}; }
|
||||||
struct copy_traits<T> {
|
struct copy_traits<T> {
|
||||||
uvalue operator()(const T& v) const {
|
uvalue operator()(const T& v) const {
|
||||||
return uvalue{v};
|
return uvalue{v};
|
||||||
|
|||||||
@@ -24,26 +24,10 @@ namespace meta_hpp::detail
|
|||||||
namespace meta_hpp::detail
|
namespace meta_hpp::detail
|
||||||
{
|
{
|
||||||
template < typename T >
|
template < typename T >
|
||||||
requires std::is_copy_constructible_v<T>
|
requires requires(const T& v) { uvalue{*v}; }
|
||||||
struct deref_traits<T*> {
|
struct deref_traits<T> {
|
||||||
uvalue operator()(T* v) const {
|
uvalue operator()(const T& v) const {
|
||||||
return v != nullptr ? uvalue{*v} : uvalue{};
|
return uvalue{*v};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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{};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,51 +24,10 @@ namespace meta_hpp::detail
|
|||||||
namespace meta_hpp::detail
|
namespace meta_hpp::detail
|
||||||
{
|
{
|
||||||
template < typename T >
|
template < typename T >
|
||||||
requires std::is_copy_constructible_v<T>
|
requires requires(const T& v, std::size_t i) { uvalue{v[i]}; }
|
||||||
struct index_traits<T*> {
|
struct index_traits<T> {
|
||||||
uvalue operator()(T* v, std::size_t i) const {
|
uvalue operator()(const T& v, std::size_t i) const {
|
||||||
// NOLINTNEXTLINE(*-pointer-arithmetic)
|
return uvalue{v[i]};
|
||||||
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{};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user