mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
implicit uvalue's ctor from value, remove all uvalue's dynamic operators
This commit is contained in:
@@ -79,5 +79,5 @@ TEST_CASE("meta/meta_examples/class/usage") {
|
||||
const meta::uvalue rectangle_v = rectangle_type.create(10, 20);
|
||||
|
||||
// calls the method with the dynamic rectangle instance 'rectangle_v'
|
||||
CHECK(rectangle_area.invoke(rectangle_v) == 200);
|
||||
CHECK(rectangle_area.invoke(rectangle_v).get_as<int>() == 200);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST_CASE("meta/meta_examples/enum/type") {
|
||||
// prints all enumerators
|
||||
std::cout << "* align" << std::endl;
|
||||
for ( auto&& [index, evalue] : align_type.get_evalues() ) {
|
||||
std::cout << " - " << index.get_name() << "/" << evalue.get_underlying_value() << std::endl;
|
||||
std::cout << " - " << index.get_name() << "/" << evalue.get_underlying_value().get_as<int>() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,5 +54,5 @@ TEST_CASE("meta/meta_examples/enum/usage") {
|
||||
CHECK(align_type.value_to_name(e) == "center");
|
||||
|
||||
// ... and back again
|
||||
CHECK(align_type.name_to_value("center") == e);
|
||||
CHECK(align_type.name_to_value("center").get_as<align>() == e);
|
||||
}
|
||||
|
||||
@@ -57,9 +57,9 @@ TEST_CASE("meta/meta_examples/inplace") {
|
||||
CHECK(ivec2_ptr.get_type() == meta::resolve_type<ivec2*>());
|
||||
|
||||
// interacts with the created object as usual
|
||||
CHECK(ivec2_x.get(ivec2_ptr) == 2);
|
||||
CHECK(ivec2_y.get(ivec2_ptr) == 3);
|
||||
CHECK(ivec2_length2(ivec2_ptr) == 13);
|
||||
CHECK(ivec2_x.get(ivec2_ptr).get_as<int>() == 2);
|
||||
CHECK(ivec2_y.get(ivec2_ptr).get_as<int>() == 3);
|
||||
CHECK(ivec2_length2(ivec2_ptr).get_as<int>() == 13);
|
||||
|
||||
// you must manually call the object's destructor
|
||||
CHECK(ivec2_type.destroy_at(ivec2_buffer.get_memory()));
|
||||
|
||||
@@ -73,7 +73,7 @@ TEST_CASE("meta/meta_examples/method/usage") {
|
||||
|
||||
// checks the type and value of the result
|
||||
CHECK(ivec2_add_result_value.get_type() == meta::resolve_type<ivec2>());
|
||||
CHECK(ivec2_add_result_value == ivec2{42, 21});
|
||||
CHECK(ivec2_add_result_value.get_as<ivec2>() == ivec2{42, 21});
|
||||
|
||||
// checks the result of our manipulations
|
||||
CHECK(v == ivec2{42, 21});
|
||||
|
||||
@@ -72,18 +72,18 @@ TEST_CASE("meta/meta_examples/scopes/local") {
|
||||
const meta::function dot3_function = math_scope.get_function("dot3");
|
||||
|
||||
// calls and checks found functions
|
||||
CHECK(dot2_function(ivec2{3,4}, ivec2{5,6}) == 39);
|
||||
CHECK(dot3_function(ivec3{3,4,5}, ivec3{6,7,8}) == 86);
|
||||
CHECK(dot2_function(ivec2{3,4}, ivec2{5,6}).get_as<int>() == 39);
|
||||
CHECK(dot3_function(ivec3{3,4,5}, ivec3{6,7,8}).get_as<int>() == 86);
|
||||
|
||||
// and free variables, of course
|
||||
const meta::variable unit2_variable = math_scope.get_variable("unit2");
|
||||
const meta::variable unit3_variable = math_scope.get_variable("unit3");
|
||||
|
||||
// checks and uses found variables with functions
|
||||
CHECK(unit2_variable.get() == ivec2{1,1});
|
||||
CHECK(unit3_variable.get() == ivec3{1,1,1});
|
||||
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()) == 2);
|
||||
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()) == 3);
|
||||
CHECK(unit2_variable.get().get_as<ivec2>() == ivec2{1,1});
|
||||
CHECK(unit3_variable.get().get_as<ivec3>() == ivec3{1,1,1});
|
||||
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()).get_as<int>() == 2);
|
||||
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()).get_as<int>() == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/scopes/global") {
|
||||
@@ -106,6 +106,6 @@ TEST_CASE("meta/meta_examples/scopes/global") {
|
||||
const meta::variable unit3_variable = math_scope.get_variable("unit3");
|
||||
|
||||
// everything works as expected
|
||||
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()) == 2);
|
||||
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()) == 3);
|
||||
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()).get_as<int>() == 2);
|
||||
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()).get_as<int>() == 3);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,6 @@ TEST_CASE("meta/meta_examples/variable/usage") {
|
||||
// prints all variables in the scope
|
||||
std::cout << "* " << constants_scope.get_name() << std::endl;
|
||||
for ( auto&& [index, variable] : constants_scope.get_variables() ) {
|
||||
std::cout << " - " << index.get_name() << ":" << variable.get() << std::endl;
|
||||
std::cout << " - " << index.get_name() << ":" << variable.get().get_as<double>() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2322,7 +2322,7 @@ namespace meta_hpp
|
||||
&& (!detail::is_in_place_type_v<Tp>)
|
||||
&& (std::is_copy_constructible_v<Tp>)
|
||||
// NOLINTNEXTLINE(*-forwarding-reference-overload)
|
||||
explicit uvalue(T&& val);
|
||||
uvalue(T&& val);
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::any_uvalue_kind<Tp>)
|
||||
@@ -2380,9 +2380,6 @@ namespace meta_hpp
|
||||
template < typename T >
|
||||
[[nodiscard]] auto try_get_as() const noexcept
|
||||
-> std::conditional_t<detail::pointer_kind<T>, T, const T*>;
|
||||
|
||||
friend std::istream& operator>>(std::istream& is, uvalue& v);
|
||||
friend std::ostream& operator<<(std::ostream& os, const uvalue& v);
|
||||
private:
|
||||
struct vtable_t;
|
||||
vtable_t* vtable_{};
|
||||
@@ -5632,7 +5629,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
for ( auto&& [_, evalue] : data_->evalues ) {
|
||||
if ( evalue.get_value() == value ) {
|
||||
if ( evalue.get_value().get_as<Enum>() == value ) {
|
||||
return evalue.get_index().get_name();
|
||||
}
|
||||
}
|
||||
@@ -8064,54 +8061,6 @@ namespace meta_hpp::detail
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
struct istream_traits;
|
||||
|
||||
template < typename T >
|
||||
concept has_istream_traits = requires(std::istream& is, T& v) {
|
||||
{ istream_traits<T>{}(is, v) } -> std::convertible_to<std::istream&>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
requires requires(std::istream& is, T& v) {
|
||||
{ is >> v } -> std::convertible_to<std::istream&>;
|
||||
}
|
||||
struct istream_traits<T> {
|
||||
std::istream& operator()(std::istream& is, T& v) const {
|
||||
return is >> v;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
struct ostream_traits;
|
||||
|
||||
template < typename T >
|
||||
concept has_ostream_traits = requires(std::ostream& os, const T& v) {
|
||||
{ ostream_traits<T>{}(os, v) } -> std::convertible_to<std::ostream&>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
requires requires(std::ostream& os, const T& v) {
|
||||
{ os << v } -> std::convertible_to<std::ostream&>;
|
||||
}
|
||||
struct ostream_traits<T> {
|
||||
std::ostream& operator()(std::ostream& os, const T& v) const {
|
||||
return os << v;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
struct uvalue::vtable_t final {
|
||||
@@ -8127,9 +8076,6 @@ namespace meta_hpp
|
||||
uvalue (*const deref)(const storage_u& from);
|
||||
uvalue (*const index)(const storage_u& from, std::size_t);
|
||||
|
||||
std::istream& (*const istream)(std::istream& is, storage_u& to);
|
||||
std::ostream& (*const ostream)(std::ostream& os, const storage_u& from);
|
||||
|
||||
template < typename T >
|
||||
static T* buffer_cast(buffer_t& buffer) noexcept {
|
||||
// NOLINTNEXTLINE(*-reinterpret-cast)
|
||||
@@ -8295,22 +8241,6 @@ namespace meta_hpp
|
||||
detail::throw_exception_with("value type doesn't have value index traits");
|
||||
}
|
||||
},
|
||||
|
||||
.istream = +[]([[maybe_unused]] std::istream& is, [[maybe_unused]] storage_u& to) -> std::istream& {
|
||||
if constexpr ( detail::has_istream_traits<Tp> && !detail::pointer_kind<Tp> ) {
|
||||
return detail::istream_traits<Tp>{}(is, *storage_cast<Tp>(to));
|
||||
} else {
|
||||
detail::throw_exception_with("value type doesn't have value istream traits");
|
||||
}
|
||||
},
|
||||
|
||||
.ostream = +[]([[maybe_unused]] std::ostream& os, [[maybe_unused]] const storage_u& from) -> std::ostream& {
|
||||
if constexpr ( detail::has_ostream_traits<Tp> && !detail::pointer_kind<Tp> ) {
|
||||
return detail::ostream_traits<Tp>{}(os, *storage_cast<Tp>(from));
|
||||
} else {
|
||||
detail::throw_exception_with("value type doesn't have value ostream traits");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return &table;
|
||||
@@ -8605,74 +8535,3 @@ namespace meta_hpp
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator<(const uvalue& l, const T& r) {
|
||||
if ( !static_cast<bool>(l) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const any_type& l_type = l.get_type();
|
||||
const any_type& r_type = resolve_type<T>();
|
||||
|
||||
return (l_type < r_type) || (l_type == r_type && l.get_as<T>() < r);
|
||||
}
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator<(const T& l, const uvalue& r) {
|
||||
if ( !static_cast<bool>(r) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const any_type& l_type = resolve_type<T>();
|
||||
const any_type& r_type = r.get_type();
|
||||
|
||||
return (l_type < r_type) || (l_type == r_type && l < r.get_as<T>());
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator==(const uvalue& l, const T& r) {
|
||||
if ( !static_cast<bool>(l) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const any_type& l_type = l.get_type();
|
||||
const any_type& r_type = resolve_type<T>();
|
||||
|
||||
return l_type == r_type && l.get_as<T>() == r;
|
||||
}
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator==(const T& l, const uvalue& r) {
|
||||
if ( !static_cast<bool>(r) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const any_type& l_type = resolve_type<T>();
|
||||
const any_type& r_type = r.get_type();
|
||||
|
||||
return l_type == r_type && l == r.get_as<T>();
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
inline std::istream& operator>>(std::istream& is, uvalue& v) {
|
||||
assert(v && "bad operator call"); // NOLINT
|
||||
return v.vtable_->istream(is, v.storage_);
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const uvalue& v) {
|
||||
assert(v && "bad operator call"); // NOLINT
|
||||
return v.vtable_->ostream(os, v.storage_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST_CASE("meta/meta_states/dtor") {
|
||||
meta::class_<clazz_dtor_metadata>()
|
||||
.destructor_({
|
||||
.metadata{
|
||||
{"desc", meta::uvalue{"virtual dtor"s}}
|
||||
{"desc", "virtual dtor"s}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -92,6 +92,6 @@ TEST_CASE("meta/meta_states/dtor") {
|
||||
CHECK(dtor.get_type().get_class_type() == meta::resolve_type<clazz_dtor_metadata>());
|
||||
CHECK(dtor.get_type().get_flags() == (meta::destructor_flags::is_noexcept | meta::destructor_flags::is_virtual));
|
||||
|
||||
CHECK(dtor.get_metadata().at("desc") == "virtual dtor"s);
|
||||
CHECK(dtor.get_metadata().at("desc").get_as<std::string>() == "virtual dtor"s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ TEST_CASE("meta/meta_states/evalue") {
|
||||
CHECK(evalue.get_type() == meta::resolve_type<color>());
|
||||
CHECK(evalue.get_name() == "green");
|
||||
|
||||
CHECK(evalue.get_value() == color::green);
|
||||
CHECK(evalue.get_value().get_as<color>() == color::green);
|
||||
CHECK(evalue.get_value().get_type() == color_type);
|
||||
|
||||
CHECK(evalue.get_underlying_value() == meta::detail::to_underlying(color::green));
|
||||
CHECK(evalue.get_underlying_value().get_as<unsigned>() == meta::detail::to_underlying(color::green));
|
||||
CHECK(evalue.get_underlying_value().get_type() == color_type.get_underlying_type());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ TEST_CASE("meta/meta_states/function") {
|
||||
CHECK_THROWS(func.invoke(ivec2{}, ivec2{}, 42));
|
||||
|
||||
CHECK(func.invoke(ivec2{1,2}, ivec2{3,4}));
|
||||
CHECK(func.invoke(ivec2{1,2}, ivec2{3,4}) == ivec2{4,6});
|
||||
CHECK(func.invoke(ivec2{1,2}, ivec2{3,4}).get_as<ivec2>() == ivec2{4,6});
|
||||
}
|
||||
|
||||
SUBCASE("ilength2") {
|
||||
@@ -113,7 +113,7 @@ TEST_CASE("meta/meta_states/function") {
|
||||
CHECK_THROWS(func.invoke(ivec2{}, 42));
|
||||
|
||||
CHECK(func.invoke(ivec2{2,3}));
|
||||
CHECK(func.invoke(ivec2{2,3}) == 13);
|
||||
CHECK(func.invoke(ivec2{2,3}).get_as<int>() == 13);
|
||||
}
|
||||
|
||||
SUBCASE("arg_null") {
|
||||
@@ -125,8 +125,8 @@ TEST_CASE("meta/meta_states/function") {
|
||||
CHECK(func.is_invocable_with<std::nullptr_t>());
|
||||
|
||||
int i{42};
|
||||
CHECK(func.invoke(&i) == false);
|
||||
CHECK(func.invoke(nullptr) == true);
|
||||
CHECK(func.invoke(&i).get_as<bool>() == false);
|
||||
CHECK(func.invoke(nullptr).get_as<bool>() == true);
|
||||
}
|
||||
|
||||
SUBCASE("arg_arr") {
|
||||
@@ -145,13 +145,13 @@ TEST_CASE("meta/meta_states/function") {
|
||||
CHECK_FALSE(func1.is_invocable_with<const ivec2*>());
|
||||
CHECK_FALSE(func1.is_invocable_with<const ivec2* const>());
|
||||
|
||||
CHECK(func1.invoke(bounded_arr) == 10);
|
||||
CHECK(func1.invoke(unbounded_arr) == 10);
|
||||
CHECK(func1.invoke(bounded_arr).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(unbounded_arr).get_as<int>() == 10);
|
||||
CHECK_THROWS(func1.invoke(bounded_const_arr));
|
||||
CHECK_THROWS(func1.invoke(unbounded_const_arr));
|
||||
|
||||
CHECK(func1.invoke(meta::uvalue{bounded_arr}) == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{unbounded_arr}) == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{bounded_arr}).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{unbounded_arr}).get_as<int>() == 10);
|
||||
CHECK_THROWS(func1.invoke(meta::uvalue{bounded_const_arr}));
|
||||
CHECK_THROWS(func1.invoke(meta::uvalue{unbounded_const_arr}));
|
||||
|
||||
@@ -170,13 +170,13 @@ TEST_CASE("meta/meta_states/function") {
|
||||
CHECK_FALSE(func2.is_invocable_with<const ivec2*>());
|
||||
CHECK_FALSE(func2.is_invocable_with<const ivec2* const>());
|
||||
|
||||
CHECK(func2.invoke(bounded_arr) == 10);
|
||||
CHECK(func2.invoke(unbounded_arr) == 10);
|
||||
CHECK(func2.invoke(bounded_arr).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(unbounded_arr).get_as<int>() == 10);
|
||||
CHECK_THROWS(func2.invoke(bounded_const_arr));
|
||||
CHECK_THROWS(func2.invoke(unbounded_const_arr));
|
||||
|
||||
CHECK(func2.invoke(meta::uvalue{bounded_arr}) == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{unbounded_arr}) == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{bounded_arr}).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{unbounded_arr}).get_as<int>() == 10);
|
||||
CHECK_THROWS(func2.invoke(meta::uvalue{bounded_const_arr}));
|
||||
CHECK_THROWS(func2.invoke(meta::uvalue{unbounded_const_arr}));
|
||||
|
||||
@@ -203,15 +203,15 @@ TEST_CASE("meta/meta_states/function") {
|
||||
CHECK(func1.is_invocable_with<const ivec2*>());
|
||||
CHECK(func1.is_invocable_with<const ivec2* const>());
|
||||
|
||||
CHECK(func1.invoke(bounded_arr) == 10);
|
||||
CHECK(func1.invoke(unbounded_arr) == 10);
|
||||
CHECK(func1.invoke(bounded_const_arr) == 10);
|
||||
CHECK(func1.invoke(unbounded_const_arr) == 10);
|
||||
CHECK(func1.invoke(bounded_arr).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(unbounded_arr).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(bounded_const_arr).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(unbounded_const_arr).get_as<int>() == 10);
|
||||
|
||||
CHECK(func1.invoke(meta::uvalue{bounded_arr}) == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{unbounded_arr}) == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{bounded_const_arr}) == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{unbounded_const_arr}) == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{bounded_arr}).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{unbounded_arr}).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{bounded_const_arr}).get_as<int>() == 10);
|
||||
CHECK(func1.invoke(meta::uvalue{unbounded_const_arr}).get_as<int>() == 10);
|
||||
|
||||
static_assert(std::is_invocable_v<decltype(&ivec2::arg_bounded_const_arr), decltype(bounded_arr)>);
|
||||
static_assert(std::is_invocable_v<decltype(&ivec2::arg_bounded_const_arr), decltype(unbounded_arr)>);
|
||||
@@ -228,15 +228,15 @@ TEST_CASE("meta/meta_states/function") {
|
||||
CHECK(func2.is_invocable_with<const ivec2*>());
|
||||
CHECK(func2.is_invocable_with<const ivec2* const>());
|
||||
|
||||
CHECK(func2.invoke(bounded_arr) == 10);
|
||||
CHECK(func2.invoke(unbounded_arr) == 10);
|
||||
CHECK(func2.invoke(bounded_const_arr) == 10);
|
||||
CHECK(func2.invoke(unbounded_const_arr) == 10);
|
||||
CHECK(func2.invoke(bounded_arr).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(unbounded_arr).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(bounded_const_arr).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(unbounded_const_arr).get_as<int>() == 10);
|
||||
|
||||
CHECK(func2.invoke(meta::uvalue{bounded_arr}) == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{unbounded_arr}) == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{bounded_const_arr}) == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{unbounded_const_arr}) == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{bounded_arr}).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{unbounded_arr}).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{bounded_const_arr}).get_as<int>() == 10);
|
||||
CHECK(func2.invoke(meta::uvalue{unbounded_const_arr}).get_as<int>() == 10);
|
||||
|
||||
static_assert(std::is_invocable_v<decltype(&ivec2::arg_unbounded_const_arr), decltype(bounded_arr)>);
|
||||
static_assert(std::is_invocable_v<decltype(&ivec2::arg_unbounded_const_arr), decltype(unbounded_arr)>);
|
||||
|
||||
@@ -79,19 +79,19 @@ TEST_CASE("meta/meta_states/member") {
|
||||
}
|
||||
|
||||
{
|
||||
CHECK(vm.get(v) == 1);
|
||||
CHECK(vm.get(&v) == 1);
|
||||
CHECK(vm.get(std::as_const(v)) == 1);
|
||||
CHECK(vm.get(&std::as_const(v)) == 1);
|
||||
CHECK(vm.get(std::move(v)) == 1);
|
||||
CHECK(vm.get(std::move(std::as_const(v))) == 1);
|
||||
CHECK(vm.get(v).get_as<int>() == 1);
|
||||
CHECK(vm.get(&v).get_as<int>() == 1);
|
||||
CHECK(vm.get(std::as_const(v)).get_as<int>() == 1);
|
||||
CHECK(vm.get(&std::as_const(v)).get_as<int>() == 1);
|
||||
CHECK(vm.get(std::move(v)).get_as<int>() == 1);
|
||||
CHECK(vm.get(std::move(std::as_const(v))).get_as<int>() == 1);
|
||||
|
||||
CHECK(vm(v) == 1);
|
||||
CHECK(vm(&v) == 1);
|
||||
CHECK(vm(std::as_const(v)) == 1);
|
||||
CHECK(vm(&std::as_const(v)) == 1);
|
||||
CHECK(vm(std::move(v)) == 1);
|
||||
CHECK(vm(std::move(std::as_const(v))) == 1);
|
||||
CHECK(vm(v).get_as<int>() == 1);
|
||||
CHECK(vm(&v).get_as<int>() == 1);
|
||||
CHECK(vm(std::as_const(v)).get_as<int>() == 1);
|
||||
CHECK(vm(&std::as_const(v)).get_as<int>() == 1);
|
||||
CHECK(vm(std::move(v)).get_as<int>() == 1);
|
||||
CHECK(vm(std::move(std::as_const(v))).get_as<int>() == 1);
|
||||
|
||||
CHECK_THROWS(std::ignore = vm.get(v2));
|
||||
CHECK_THROWS(std::ignore = vm.get(&v2));
|
||||
@@ -136,27 +136,27 @@ TEST_CASE("meta/meta_states/member") {
|
||||
}
|
||||
|
||||
{
|
||||
vm.set(v, 10); CHECK(vm.get(v) == 10);
|
||||
vm.set(&v, 100); CHECK(vm.get(v) == 100);
|
||||
CHECK_THROWS(vm.set(std::as_const(v), 11)); CHECK(vm.get(v) == 100);
|
||||
CHECK_THROWS(vm.set(&std::as_const(v), 11)); CHECK(vm.get(v) == 100);
|
||||
vm.set(v, 10); CHECK(vm.get(v).get_as<int>() == 10);
|
||||
vm.set(&v, 100); CHECK(vm.get(v).get_as<int>() == 100);
|
||||
CHECK_THROWS(vm.set(std::as_const(v), 11)); CHECK(vm.get(v).get_as<int>() == 100);
|
||||
CHECK_THROWS(vm.set(&std::as_const(v), 11)); CHECK(vm.get(v).get_as<int>() == 100);
|
||||
|
||||
vm.set(std::move(v), 12); CHECK(vm.get(v) == 12);
|
||||
CHECK_THROWS(vm.set(std::move(std::as_const(v)), 13)); CHECK(vm.get(v) == 12);
|
||||
vm.set(std::move(v), 12); CHECK(vm.get(v).get_as<int>() == 12);
|
||||
CHECK_THROWS(vm.set(std::move(std::as_const(v)), 13)); CHECK(vm.get(v).get_as<int>() == 12);
|
||||
|
||||
vm(v, 13); CHECK(vm(v) == 13);
|
||||
vm(&v, 130); CHECK(vm(v) == 130);
|
||||
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v) == 130);
|
||||
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v) == 130);
|
||||
vm(v, 13); CHECK(vm(v).get_as<int>() == 13);
|
||||
vm(&v, 130); CHECK(vm(v).get_as<int>() == 130);
|
||||
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v).get_as<int>() == 130);
|
||||
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v).get_as<int>() == 130);
|
||||
|
||||
vm(std::move(v), 15); CHECK(vm(v) == 15);
|
||||
CHECK_THROWS(vm(std::move(std::as_const(v)), 16)); CHECK(vm(v) == 15);
|
||||
vm(std::move(v), 15); CHECK(vm(v).get_as<int>() == 15);
|
||||
CHECK_THROWS(vm(std::move(std::as_const(v)), 16)); CHECK(vm(v).get_as<int>() == 15);
|
||||
|
||||
CHECK_THROWS(vm.set(v2, 17));
|
||||
CHECK_THROWS(vm.set(&v2, 17));
|
||||
CHECK_THROWS(vm(v2, 17));
|
||||
CHECK_THROWS(vm(&v2, 17));
|
||||
CHECK(vm(v) == 15);
|
||||
CHECK(vm(v).get_as<int>() == 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,19 +194,19 @@ TEST_CASE("meta/meta_states/member") {
|
||||
}
|
||||
|
||||
{
|
||||
CHECK(vm.get(v) == 2);
|
||||
CHECK(vm.get(&v) == 2);
|
||||
CHECK(vm.get(std::as_const(v)) == 2);
|
||||
CHECK(vm.get(&std::as_const(v)) == 2);
|
||||
CHECK(vm.get(std::move(v)) == 2);
|
||||
CHECK(vm.get(std::move(std::as_const(v))) == 2);
|
||||
CHECK(vm.get(v).get_as<int>() == 2);
|
||||
CHECK(vm.get(&v).get_as<int>() == 2);
|
||||
CHECK(vm.get(std::as_const(v)).get_as<int>() == 2);
|
||||
CHECK(vm.get(&std::as_const(v)).get_as<int>() == 2);
|
||||
CHECK(vm.get(std::move(v)).get_as<int>() == 2);
|
||||
CHECK(vm.get(std::move(std::as_const(v))).get_as<int>() == 2);
|
||||
|
||||
CHECK(vm(v) == 2);
|
||||
CHECK(vm(&v) == 2);
|
||||
CHECK(vm(std::as_const(v)) == 2);
|
||||
CHECK(vm(&std::as_const(v)) == 2);
|
||||
CHECK(vm(std::move(v)) == 2);
|
||||
CHECK(vm(std::move(std::as_const(v))) == 2);
|
||||
CHECK(vm(v).get_as<int>() == 2);
|
||||
CHECK(vm(&v).get_as<int>() == 2);
|
||||
CHECK(vm(std::as_const(v)).get_as<int>() == 2);
|
||||
CHECK(vm(&std::as_const(v)).get_as<int>() == 2);
|
||||
CHECK(vm(std::move(v)).get_as<int>() == 2);
|
||||
CHECK(vm(std::move(std::as_const(v))).get_as<int>() == 2);
|
||||
|
||||
CHECK_THROWS(std::ignore = vm.get(v2));
|
||||
CHECK_THROWS(std::ignore = vm.get(&v2));
|
||||
@@ -247,25 +247,25 @@ TEST_CASE("meta/meta_states/member") {
|
||||
}
|
||||
|
||||
{
|
||||
CHECK_THROWS(vm.set(v, 10)); CHECK(vm.get(v) == 2);
|
||||
CHECK_THROWS(vm.set(&v, 10)); CHECK(vm.get(v) == 2);
|
||||
CHECK_THROWS(vm.set(std::as_const(v), 11)); CHECK(vm.get(v) == 2);
|
||||
CHECK_THROWS(vm.set(&std::as_const(v), 11)); CHECK(vm.get(v) == 2);
|
||||
CHECK_THROWS(vm.set(std::move(v), 12)); CHECK(vm.get(v) == 2);
|
||||
CHECK_THROWS(vm.set(std::move(std::as_const(v)), 16)); CHECK(vm.get(v) == 2);
|
||||
CHECK_THROWS(vm.set(v, 10)); CHECK(vm.get(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm.set(&v, 10)); CHECK(vm.get(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm.set(std::as_const(v), 11)); CHECK(vm.get(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm.set(&std::as_const(v), 11)); CHECK(vm.get(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm.set(std::move(v), 12)); CHECK(vm.get(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm.set(std::move(std::as_const(v)), 16)); CHECK(vm.get(v).get_as<int>() == 2);
|
||||
|
||||
CHECK_THROWS(vm(v, 13)); CHECK(vm(v) == 2);
|
||||
CHECK_THROWS(vm(&v, 13)); CHECK(vm(v) == 2);
|
||||
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v) == 2);
|
||||
CHECK_THROWS(vm(&std::as_const(v), 14)); CHECK(vm(v) == 2);
|
||||
CHECK_THROWS(vm(std::move(v), 15)); CHECK(vm(v) == 2);
|
||||
CHECK_THROWS(vm(std::move(std::as_const(v)), 16)); CHECK(vm(v) == 2);
|
||||
CHECK_THROWS(vm(v, 13)); CHECK(vm(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm(&v, 13)); CHECK(vm(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm(&std::as_const(v), 14)); CHECK(vm(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm(std::move(v), 15)); CHECK(vm(v).get_as<int>() == 2);
|
||||
CHECK_THROWS(vm(std::move(std::as_const(v)), 16)); CHECK(vm(v).get_as<int>() == 2);
|
||||
|
||||
CHECK_THROWS(vm.set(v2, 17));
|
||||
CHECK_THROWS(vm.set(&v2, 17));
|
||||
CHECK_THROWS(vm(v2, 17));
|
||||
CHECK_THROWS(vm(&v2, 17));
|
||||
CHECK(vm(v) == 2);
|
||||
CHECK(vm(v).get_as<int>() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,13 +279,13 @@ TEST_CASE("meta/meta_states/member") {
|
||||
{
|
||||
clazz_1 v;
|
||||
CHECK(vm.get(v).get_type() == meta::resolve_type<std::unique_ptr<int>*>());
|
||||
CHECK(vm.get(v) == std::addressof(v.unique_int_member));
|
||||
CHECK(vm.get(v).get_as<std::unique_ptr<int>*>() == std::addressof(v.unique_int_member));
|
||||
}
|
||||
|
||||
{
|
||||
const clazz_1 v;
|
||||
CHECK(vm.get(v).get_type() == meta::resolve_type<const std::unique_ptr<int>*>());
|
||||
CHECK(vm.get(v) == std::addressof(v.unique_int_member));
|
||||
CHECK(vm.get(v).get_as<const std::unique_ptr<int>*>() == std::addressof(v.unique_int_member));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,30 +38,30 @@ TEST_CASE("meta/meta_states/metadata/enum") {
|
||||
using namespace std::string_literals;
|
||||
|
||||
meta::enum_<color>({
|
||||
{"desc1", meta::uvalue{"enum-desc1"s}},
|
||||
{"desc2", meta::uvalue{"enum-desc2"s}},
|
||||
{"desc1", "enum-desc1"s},
|
||||
{"desc2", "enum-desc2"s},
|
||||
})
|
||||
.evalue_("red", color::red, {
|
||||
.metadata{{"desc1", meta::uvalue{"red-color"s}}}
|
||||
.metadata{{"desc1", "red-color"s}}
|
||||
})
|
||||
.evalue_("green", color::green, {
|
||||
.metadata{{"desc1", meta::uvalue{"green-color"s}}}
|
||||
.metadata{{"desc1", "green-color"s}}
|
||||
})
|
||||
.evalue_("blue", color::blue, {
|
||||
.metadata{{"desc1", meta::uvalue{"blue-color"s}}}
|
||||
.metadata{{"desc1", "blue-color"s}}
|
||||
});
|
||||
|
||||
// metadata override
|
||||
|
||||
meta::enum_<color>({
|
||||
{"desc2", meta::uvalue{"new-enum-desc2"s}},
|
||||
{"desc3", meta::uvalue{"new-enum-desc3"s}},
|
||||
{"desc2", "new-enum-desc2"s},
|
||||
{"desc3", "new-enum-desc3"s},
|
||||
});
|
||||
|
||||
meta::enum_<color>()
|
||||
.evalue_("red", color::red, {
|
||||
.metadata{
|
||||
{"desc2", meta::uvalue{"new-red-color"s}},
|
||||
{"desc2", "new-red-color"s},
|
||||
}
|
||||
});
|
||||
|
||||
@@ -71,16 +71,16 @@ TEST_CASE("meta/meta_states/metadata/enum") {
|
||||
REQUIRE(color_type);
|
||||
|
||||
SUBCASE("color") {
|
||||
CHECK(color_type.get_metadata().at("desc1") == "enum-desc1"s);
|
||||
CHECK(color_type.get_metadata().at("desc2") == "new-enum-desc2"s);
|
||||
CHECK(color_type.get_metadata().at("desc3") == "new-enum-desc3"s);
|
||||
CHECK(color_type.get_metadata().at("desc1").get_as<std::string>() == "enum-desc1"s);
|
||||
CHECK(color_type.get_metadata().at("desc2").get_as<std::string>() == "new-enum-desc2"s);
|
||||
CHECK(color_type.get_metadata().at("desc3").get_as<std::string>() == "new-enum-desc3"s);
|
||||
}
|
||||
|
||||
SUBCASE("color::red") {
|
||||
const meta::evalue red_evalue = color_type.get_evalue("red");
|
||||
REQUIRE(red_evalue);
|
||||
CHECK_FALSE(red_evalue.get_metadata().contains("desc1"));
|
||||
CHECK(red_evalue.get_metadata().at("desc2") == "new-red-color"s);
|
||||
CHECK(red_evalue.get_metadata().at("desc2").get_as<std::string>() == "new-red-color"s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,55 +89,55 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
using namespace std::string_literals;
|
||||
|
||||
meta::class_<ivec2>({
|
||||
{"desc1", meta::uvalue{"class-desc1"s}},
|
||||
{"desc2", meta::uvalue{"class-desc2"s}},
|
||||
{"desc1", "class-desc1"s},
|
||||
{"desc2", "class-desc2"s},
|
||||
})
|
||||
.constructor_<int>({
|
||||
.arguments{{
|
||||
.name{"v"},
|
||||
.metadata{{"desc", meta::uvalue{"the ctor arg"s}}},
|
||||
.metadata{{"desc", "the ctor arg"s}},
|
||||
}},
|
||||
.metadata{{"desc", meta::uvalue{"one arg 2d vector ctor"s}}},
|
||||
.metadata{{"desc", "one arg 2d vector ctor"s}},
|
||||
})
|
||||
.constructor_<int, int>({
|
||||
.arguments{{
|
||||
.name{"x"},
|
||||
.metadata{{"desc", meta::uvalue{"the 1st ctor arg"s}}},
|
||||
.metadata{{"desc", "the 1st ctor arg"s}},
|
||||
},{
|
||||
.name{"y"},
|
||||
.metadata{{"desc", meta::uvalue{"the 2nd ctor arg"s}}},
|
||||
.metadata{{"desc", "the 2nd ctor arg"s}},
|
||||
}},
|
||||
.metadata{{"desc", meta::uvalue{"two args 2d vector ctor"s}}}
|
||||
.metadata{{"desc", "two args 2d vector ctor"s}}
|
||||
})
|
||||
.member_("x", &ivec2::x, {
|
||||
.metadata{{"desc", meta::uvalue{"x-member"s}}}
|
||||
.metadata{{"desc", "x-member"s}}
|
||||
})
|
||||
.member_("y", &ivec2::y, {
|
||||
.metadata{{"desc", meta::uvalue{"y-member"s}}}
|
||||
.metadata{{"desc", "y-member"s}}
|
||||
})
|
||||
.method_("add", &ivec2::add, {
|
||||
.arguments{{
|
||||
.name{"other"},
|
||||
.metadata{{"desc", meta::uvalue{"other-arg"s}}}
|
||||
.metadata{{"desc", "other-arg"s}}
|
||||
}},
|
||||
.metadata{{"desc", meta::uvalue{"add-method"s}}}
|
||||
.metadata{{"desc", "add-method"s}}
|
||||
})
|
||||
.function_("iadd", &ivec2::iadd, {
|
||||
.arguments{{
|
||||
.name{"l"},
|
||||
.metadata{{"desc", meta::uvalue{"l-arg"s}}}
|
||||
.metadata{{"desc", "l-arg"s}}
|
||||
},{
|
||||
.name{"r"},
|
||||
.metadata{{"desc", meta::uvalue{"r-arg"s}}}
|
||||
.metadata{{"desc", "r-arg"s}}
|
||||
}},
|
||||
.metadata{{"desc", meta::uvalue{"iadd-function"s}}}
|
||||
.metadata{{"desc", "iadd-function"s}}
|
||||
});
|
||||
|
||||
// metadata override
|
||||
|
||||
meta::class_<ivec2>({
|
||||
{"desc2", meta::uvalue{"new-class-desc2"s}},
|
||||
{"desc3", meta::uvalue{"new-class-desc3"s}},
|
||||
{"desc2", "new-class-desc2"s},
|
||||
{"desc3", "new-class-desc3"s},
|
||||
});
|
||||
|
||||
//
|
||||
@@ -146,9 +146,9 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
REQUIRE(ivec2_type);
|
||||
|
||||
SUBCASE("ivec2") {
|
||||
CHECK(ivec2_type.get_metadata().at("desc1") == "class-desc1"s);
|
||||
CHECK(ivec2_type.get_metadata().at("desc2") == "new-class-desc2"s);
|
||||
CHECK(ivec2_type.get_metadata().at("desc3") == "new-class-desc3"s);
|
||||
CHECK(ivec2_type.get_metadata().at("desc1").get_as<std::string>() == "class-desc1"s);
|
||||
CHECK(ivec2_type.get_metadata().at("desc2").get_as<std::string>() == "new-class-desc2"s);
|
||||
CHECK(ivec2_type.get_metadata().at("desc3").get_as<std::string>() == "new-class-desc3"s);
|
||||
}
|
||||
|
||||
SUBCASE("ivec2(int)") {
|
||||
@@ -156,14 +156,14 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
REQUIRE(ivec2_ctor);
|
||||
|
||||
REQUIRE(ivec2_ctor.get_metadata().contains("desc"));
|
||||
CHECK(ivec2_ctor.get_metadata().at("desc") == "one arg 2d vector ctor"s);
|
||||
CHECK(ivec2_ctor.get_metadata().at("desc").get_as<std::string>() == "one arg 2d vector ctor"s);
|
||||
|
||||
REQUIRE(ivec2_ctor.get_argument(0));
|
||||
CHECK(ivec2_ctor.get_argument(0).get_name() == "v");
|
||||
CHECK(ivec2_ctor.get_argument(0).get_position() == 0);
|
||||
CHECK(ivec2_ctor.get_argument(0).get_type() == meta::resolve_type<int>());
|
||||
REQUIRE(ivec2_ctor.get_argument(0).get_metadata().contains("desc"));
|
||||
CHECK(ivec2_ctor.get_argument(0).get_metadata().at("desc") == "the ctor arg"s);
|
||||
CHECK(ivec2_ctor.get_argument(0).get_metadata().at("desc").get_as<std::string>() == "the ctor arg"s);
|
||||
|
||||
REQUIRE_FALSE(ivec2_ctor.get_argument(1));
|
||||
}
|
||||
@@ -173,21 +173,21 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
REQUIRE(ivec2_ctor);
|
||||
|
||||
REQUIRE(ivec2_ctor.get_metadata().contains("desc"));
|
||||
CHECK(ivec2_ctor.get_metadata().at("desc") == "two args 2d vector ctor"s);
|
||||
CHECK(ivec2_ctor.get_metadata().at("desc").get_as<std::string>() == "two args 2d vector ctor"s);
|
||||
|
||||
REQUIRE(ivec2_ctor.get_argument(0));
|
||||
CHECK(ivec2_ctor.get_argument(0).get_name() == "x");
|
||||
CHECK(ivec2_ctor.get_argument(0).get_position() == 0);
|
||||
CHECK(ivec2_ctor.get_argument(0).get_type() == meta::resolve_type<int>());
|
||||
REQUIRE(ivec2_ctor.get_argument(0).get_metadata().contains("desc"));
|
||||
CHECK(ivec2_ctor.get_argument(0).get_metadata().at("desc") == "the 1st ctor arg"s);
|
||||
CHECK(ivec2_ctor.get_argument(0).get_metadata().at("desc").get_as<std::string>() == "the 1st ctor arg"s);
|
||||
|
||||
REQUIRE(ivec2_ctor.get_argument(1));
|
||||
CHECK(ivec2_ctor.get_argument(1).get_name() == "y");
|
||||
CHECK(ivec2_ctor.get_argument(1).get_position() == 1);
|
||||
CHECK(ivec2_ctor.get_argument(1).get_type() == meta::resolve_type<int>());
|
||||
REQUIRE(ivec2_ctor.get_argument(1).get_metadata().contains("desc"));
|
||||
CHECK(ivec2_ctor.get_argument(1).get_metadata().at("desc") == "the 2nd ctor arg"s);
|
||||
CHECK(ivec2_ctor.get_argument(1).get_metadata().at("desc").get_as<std::string>() == "the 2nd ctor arg"s);
|
||||
|
||||
REQUIRE_FALSE(ivec2_ctor.get_argument(2));
|
||||
}
|
||||
@@ -197,7 +197,7 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
REQUIRE(ivec2_x);
|
||||
|
||||
REQUIRE(ivec2_x.get_metadata().contains("desc"));
|
||||
CHECK(ivec2_x.get_metadata().at("desc") == "x-member"s);
|
||||
CHECK(ivec2_x.get_metadata().at("desc").get_as<std::string>() == "x-member"s);
|
||||
}
|
||||
|
||||
SUBCASE("ivec2::y") {
|
||||
@@ -205,7 +205,7 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
REQUIRE(ivec2_y);
|
||||
|
||||
REQUIRE(ivec2_y.get_metadata().contains("desc"));
|
||||
CHECK(ivec2_y.get_metadata().at("desc") == "y-member"s);
|
||||
CHECK(ivec2_y.get_metadata().at("desc").get_as<std::string>() == "y-member"s);
|
||||
}
|
||||
|
||||
SUBCASE("ivec2::add") {
|
||||
@@ -213,11 +213,11 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
REQUIRE(ivec2_add);
|
||||
|
||||
REQUIRE(ivec2_add.get_metadata().contains("desc"));
|
||||
CHECK(ivec2_add.get_metadata().at("desc") == "add-method"s);
|
||||
CHECK(ivec2_add.get_metadata().at("desc").get_as<std::string>() == "add-method"s);
|
||||
|
||||
REQUIRE(ivec2_add.get_argument(0));
|
||||
REQUIRE(ivec2_add.get_argument(0).get_metadata().contains("desc"));
|
||||
CHECK(ivec2_add.get_argument(0).get_metadata().at("desc") == "other-arg"s);
|
||||
CHECK(ivec2_add.get_argument(0).get_metadata().at("desc").get_as<std::string>() == "other-arg"s);
|
||||
}
|
||||
|
||||
SUBCASE("ivec2::iadd") {
|
||||
@@ -225,15 +225,15 @@ TEST_CASE("meta/meta_states/metadata/class") {
|
||||
REQUIRE(ivec2_iadd);
|
||||
|
||||
REQUIRE(ivec2_iadd.get_metadata().contains("desc"));
|
||||
CHECK(ivec2_iadd.get_metadata().at("desc") == "iadd-function"s);
|
||||
CHECK(ivec2_iadd.get_metadata().at("desc").get_as<std::string>() == "iadd-function"s);
|
||||
|
||||
REQUIRE(ivec2_iadd.get_argument(0));
|
||||
REQUIRE(ivec2_iadd.get_argument(0).get_metadata().contains("desc"));
|
||||
CHECK(ivec2_iadd.get_argument(0).get_metadata().at("desc") == "l-arg"s);
|
||||
CHECK(ivec2_iadd.get_argument(0).get_metadata().at("desc").get_as<std::string>() == "l-arg"s);
|
||||
|
||||
REQUIRE(ivec2_iadd.get_argument(1));
|
||||
REQUIRE(ivec2_iadd.get_argument(1).get_metadata().contains("desc"));
|
||||
CHECK(ivec2_iadd.get_argument(1).get_metadata().at("desc") == "r-arg"s);
|
||||
CHECK(ivec2_iadd.get_argument(1).get_metadata().at("desc").get_as<std::string>() == "r-arg"s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,16 +243,16 @@ TEST_CASE("meta/meta_states/metadata/scope") {
|
||||
|
||||
SUBCASE("local_scope") {
|
||||
const meta::scope lscope = meta::local_scope_("local-scope", {
|
||||
{"desc", meta::uvalue{"scope-desc"s}}
|
||||
{"desc", "scope-desc"s}
|
||||
});
|
||||
CHECK(lscope.get_metadata().at("desc") == "scope-desc"s);
|
||||
CHECK(lscope.get_metadata().at("desc").get_as<std::string>() == "scope-desc"s);
|
||||
}
|
||||
|
||||
SUBCASE("static_scope") {
|
||||
meta::static_scope_("meta/meta_states/metadata/scope/static-scope", {
|
||||
{"desc", meta::uvalue{"scope-desc"s}}
|
||||
{"desc", "scope-desc"s}
|
||||
});
|
||||
CHECK(meta::resolve_scope("meta/meta_states/metadata/scope/static-scope").get_metadata().at("desc") == "scope-desc"s);
|
||||
CHECK(meta::resolve_scope("meta/meta_states/metadata/scope/static-scope").get_metadata().at("desc").get_as<std::string>() == "scope-desc"s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,64 +262,64 @@ TEST_CASE("meta/meta_states/metadata/other") {
|
||||
|
||||
SUBCASE("array") {
|
||||
meta::array_<int[]>({
|
||||
{"desc", meta::uvalue{"int[]-type"s}}
|
||||
{"desc", "int[]-type"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<int[]>().get_metadata().at("desc") == "int[]-type"s);
|
||||
CHECK(meta::resolve_type<int[]>().get_metadata().at("desc").get_as<std::string>() == "int[]-type"s);
|
||||
}
|
||||
|
||||
SUBCASE("function") {
|
||||
meta::function_<int(*)(int)>({
|
||||
{"desc", meta::uvalue{"int->int"s}}
|
||||
{"desc", "int->int"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<int(*)(int)>().get_metadata().at("desc") == "int->int"s);
|
||||
CHECK(meta::resolve_type<int(*)(int)>().get_metadata().at("desc").get_as<std::string>() == "int->int"s);
|
||||
}
|
||||
|
||||
SUBCASE("member") {
|
||||
meta::member_<int ivec2::*>({
|
||||
{"desc", meta::uvalue{"ivec2::int"s}}
|
||||
{"desc", "ivec2::int"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<int ivec2::*>().get_metadata().at("desc") == "ivec2::int"s);
|
||||
CHECK(meta::resolve_type<int ivec2::*>().get_metadata().at("desc").get_as<std::string>() == "ivec2::int"s);
|
||||
}
|
||||
|
||||
SUBCASE("method") {
|
||||
meta::method_<int (ivec2::*)(int)>({
|
||||
{"desc", meta::uvalue{"ivec2(int -> int)"s}}
|
||||
{"desc", "ivec2(int -> int)"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<int (ivec2::*)(int)>().get_metadata().at("desc") == "ivec2(int -> int)"s);
|
||||
CHECK(meta::resolve_type<int (ivec2::*)(int)>().get_metadata().at("desc").get_as<std::string>() == "ivec2(int -> int)"s);
|
||||
}
|
||||
|
||||
SUBCASE("nullptr") {
|
||||
meta::nullptr_<std::nullptr_t>({
|
||||
{"desc", meta::uvalue{"nullptr_t"s}}
|
||||
{"desc", "nullptr_t"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<std::nullptr_t>().get_metadata().at("desc") == "nullptr_t"s);
|
||||
CHECK(meta::resolve_type<std::nullptr_t>().get_metadata().at("desc").get_as<std::string>() == "nullptr_t"s);
|
||||
}
|
||||
|
||||
SUBCASE("number") {
|
||||
meta::number_<int>({
|
||||
{"desc", meta::uvalue{"int-type"s}}
|
||||
{"desc", "int-type"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<int>().get_metadata().at("desc") == "int-type"s);
|
||||
CHECK(meta::resolve_type<int>().get_metadata().at("desc").get_as<std::string>() == "int-type"s);
|
||||
}
|
||||
|
||||
SUBCASE("pointer") {
|
||||
meta::pointer_<int*>({
|
||||
{"desc", meta::uvalue{"int*-type"s}}
|
||||
{"desc", "int*-type"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<int*>().get_metadata().at("desc") == "int*-type"s);
|
||||
CHECK(meta::resolve_type<int*>().get_metadata().at("desc").get_as<std::string>() == "int*-type"s);
|
||||
}
|
||||
|
||||
SUBCASE("reference") {
|
||||
meta::reference_<int&>({
|
||||
{"desc", meta::uvalue{"int&-type"s}}
|
||||
{"desc", "int&-type"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<int&>().get_metadata().at("desc") == "int&-type"s);
|
||||
CHECK(meta::resolve_type<int&>().get_metadata().at("desc").get_as<std::string>() == "int&-type"s);
|
||||
}
|
||||
|
||||
SUBCASE("void") {
|
||||
meta::void_<void>({
|
||||
{"desc", meta::uvalue{"void-type"s}}
|
||||
{"desc", "void-type"s}
|
||||
});
|
||||
CHECK(meta::resolve_type<void>().get_metadata().at("desc") == "void-type"s);
|
||||
CHECK(meta::resolve_type<void>().get_metadata().at("desc").get_as<std::string>() == "void-type"s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,14 +143,14 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 1);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 1);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK(mi.invoke(std::move(cl)) == 1);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 1);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(cl))));
|
||||
|
||||
CHECK(mi.invoke(clv) == 1);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 1);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK(mi.invoke(std::move(clv)) == 1);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 1);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(clv))));
|
||||
}
|
||||
|
||||
@@ -163,15 +163,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 1);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 1);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 1);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 1);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 1);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 1);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 1);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 1);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 1);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 1);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 1);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 1);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 1);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 1);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 1);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 1);
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl2));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl2)));
|
||||
@@ -229,14 +229,14 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 2);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 2);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK(mi.invoke(std::move(cl)) == 2);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 2);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(cl))));
|
||||
|
||||
CHECK(mi.invoke(clv) == 2);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 2);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK(mi.invoke(std::move(clv)) == 2);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 2);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(clv))));
|
||||
}
|
||||
|
||||
@@ -249,15 +249,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 2);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 2);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 2);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 2);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 2);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 2);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 2);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 2);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 2);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 2);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 2);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 2);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 2);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 2);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 2);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 2);
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl2));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl2)));
|
||||
@@ -315,15 +315,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl)) == 3);
|
||||
CHECK(mi.invoke(std::move(cl)) == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))) == 3);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))).get_as<int>() == 3);
|
||||
|
||||
CHECK(mi.invoke(clv) == 3);
|
||||
CHECK(mi.invoke(std::as_const(clv)) == 3);
|
||||
CHECK(mi.invoke(std::move(clv)) == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))) == 3);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::as_const(clv)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))).get_as<int>() == 3);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -335,25 +335,25 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 3);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 3);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 3);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 3);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 3);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 3);
|
||||
|
||||
CHECK(mi.invoke(cl2) == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl2)) == 3);
|
||||
CHECK(mi.invoke(std::move(cl2)) == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))) == 3);
|
||||
CHECK(mi.invoke(cl2).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl2)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(cl2)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))).get_as<int>() == 3);
|
||||
|
||||
CHECK(mi.invoke(cl2v) == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)) == 3);
|
||||
CHECK(mi.invoke(std::move(cl2v)) == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))) == 3);
|
||||
CHECK(mi.invoke(cl2v).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(cl2v)).get_as<int>() == 3);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))).get_as<int>() == 3);
|
||||
}
|
||||
|
||||
static_assert(std::is_invocable_v<decltype(&clazz::const_method), clazz&>);
|
||||
@@ -401,15 +401,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl)) == 4);
|
||||
CHECK(mi.invoke(std::move(cl)) == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))) == 4);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))).get_as<int>() == 4);
|
||||
|
||||
CHECK(mi.invoke(clv) == 4);
|
||||
CHECK(mi.invoke(std::as_const(clv)) == 4);
|
||||
CHECK(mi.invoke(std::move(clv)) == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))) == 4);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::as_const(clv)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))).get_as<int>() == 4);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -421,25 +421,25 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 4);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 4);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 4);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 4);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 4);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 4);
|
||||
|
||||
CHECK(mi.invoke(cl2) == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl2)) == 4);
|
||||
CHECK(mi.invoke(std::move(cl2)) == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))) == 4);
|
||||
CHECK(mi.invoke(cl2).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl2)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(cl2)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))).get_as<int>() == 4);
|
||||
|
||||
CHECK(mi.invoke(cl2v) == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)) == 4);
|
||||
CHECK(mi.invoke(std::move(cl2v)) == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))) == 4);
|
||||
CHECK(mi.invoke(cl2v).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(cl2v)).get_as<int>() == 4);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))).get_as<int>() == 4);
|
||||
}
|
||||
|
||||
static_assert(std::is_invocable_v<decltype(&clazz::const_method_noexcept), clazz&>);
|
||||
@@ -482,12 +482,12 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 5);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 5);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK_THROWS(mi.invoke(std::move(cl)));
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(cl))));
|
||||
|
||||
CHECK(mi.invoke(clv) == 5);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 5);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK_THROWS(mi.invoke(std::move(clv)));
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(clv))));
|
||||
@@ -502,15 +502,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 5);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 5);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 5);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 5);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 5);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 5);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 5);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 5);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 5);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 5);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 5);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 5);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 5);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 5);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 5);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 5);
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl2));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl2)));
|
||||
@@ -563,12 +563,12 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 6);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 6);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK_THROWS(mi.invoke(std::move(cl)));
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(cl))));
|
||||
|
||||
CHECK(mi.invoke(clv) == 6);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 6);
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK_THROWS(mi.invoke(std::move(clv)));
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(clv))));
|
||||
@@ -583,15 +583,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 6);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 6);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 6);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 6);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 6);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 6);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 6);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 6);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 6);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 6);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 6);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 6);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 6);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 6);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 6);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 6);
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl2));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl2)));
|
||||
@@ -644,15 +644,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl)) == 7);
|
||||
CHECK(mi.invoke(std::move(cl)) == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))) == 7);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))).get_as<int>() == 7);
|
||||
|
||||
CHECK(mi.invoke(clv) == 7);
|
||||
CHECK(mi.invoke(std::as_const(clv)) == 7);
|
||||
CHECK(mi.invoke(std::move(clv)) == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))) == 7);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::as_const(clv)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))).get_as<int>() == 7);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -664,25 +664,25 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 7);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 7);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 7);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 7);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 7);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 7);
|
||||
|
||||
CHECK(mi.invoke(cl2) == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl2)) == 7);
|
||||
CHECK(mi.invoke(std::move(cl2)) == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))) == 7);
|
||||
CHECK(mi.invoke(cl2).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl2)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(cl2)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))).get_as<int>() == 7);
|
||||
|
||||
CHECK(mi.invoke(cl2v) == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)) == 7);
|
||||
CHECK(mi.invoke(std::move(cl2v)) == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))) == 7);
|
||||
CHECK(mi.invoke(cl2v).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(cl2v)).get_as<int>() == 7);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))).get_as<int>() == 7);
|
||||
}
|
||||
|
||||
static_assert(std::is_invocable_v<decltype(&clazz::const_method_ref), clazz&>);
|
||||
@@ -725,15 +725,15 @@ TEST_CASE("meta/meta_states/method") {
|
||||
derived_clazz cl;
|
||||
meta::uvalue clv{cl};
|
||||
|
||||
CHECK(mi.invoke(cl) == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl)) == 8);
|
||||
CHECK(mi.invoke(std::move(cl)) == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))) == 8);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))).get_as<int>() == 8);
|
||||
|
||||
CHECK(mi.invoke(clv) == 8);
|
||||
CHECK(mi.invoke(std::as_const(clv)) == 8);
|
||||
CHECK(mi.invoke(std::move(clv)) == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))) == 8);
|
||||
CHECK(mi.invoke(clv).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::as_const(clv)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))).get_as<int>() == 8);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -745,25 +745,25 @@ TEST_CASE("meta/meta_states/method") {
|
||||
meta::uvalue cl1v{cl1};
|
||||
meta::uvalue cl2v{cl2};
|
||||
|
||||
CHECK(mi.invoke(cl1) == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl1)) == 8);
|
||||
CHECK(mi.invoke(std::move(cl1)) == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))) == 8);
|
||||
CHECK(mi.invoke(cl1).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl1)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(cl1)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1))).get_as<int>() == 8);
|
||||
|
||||
CHECK(mi.invoke(cl1v) == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)) == 8);
|
||||
CHECK(mi.invoke(std::move(cl1v)) == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))) == 8);
|
||||
CHECK(mi.invoke(cl1v).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl1v)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(cl1v)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as<int>() == 8);
|
||||
|
||||
CHECK(mi.invoke(cl2) == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl2)) == 8);
|
||||
CHECK(mi.invoke(std::move(cl2)) == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))) == 8);
|
||||
CHECK(mi.invoke(cl2).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl2)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(cl2)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2))).get_as<int>() == 8);
|
||||
|
||||
CHECK(mi.invoke(cl2v) == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)) == 8);
|
||||
CHECK(mi.invoke(std::move(cl2v)) == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))) == 8);
|
||||
CHECK(mi.invoke(cl2v).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::as_const(cl2v)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(cl2v)).get_as<int>() == 8);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl2v))).get_as<int>() == 8);
|
||||
}
|
||||
|
||||
static_assert(std::is_invocable_v<decltype(&clazz::const_method_noexcept_ref), clazz&>);
|
||||
@@ -808,12 +808,12 @@ TEST_CASE("meta/meta_states/method") {
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK(mi.invoke(std::move(cl)) == 9);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 9);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(cl))));
|
||||
|
||||
CHECK_THROWS(mi.invoke(clv));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK(mi.invoke(std::move(clv)) == 9);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 9);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(clv))));
|
||||
}
|
||||
|
||||
@@ -889,12 +889,12 @@ TEST_CASE("meta/meta_states/method") {
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK(mi.invoke(std::move(cl)) == 10);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 10);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(cl))));
|
||||
|
||||
CHECK_THROWS(mi.invoke(clv));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK(mi.invoke(std::move(clv)) == 10);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 10);
|
||||
CHECK_THROWS(mi.invoke(std::move(std::as_const(clv))));
|
||||
}
|
||||
|
||||
@@ -970,13 +970,13 @@ TEST_CASE("meta/meta_states/method") {
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK(mi.invoke(std::move(cl)) == 11);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))) == 11);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 11);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))).get_as<int>() == 11);
|
||||
|
||||
CHECK_THROWS(mi.invoke(clv));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK(mi.invoke(std::move(clv)) == 11);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))) == 11);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 11);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))).get_as<int>() == 11);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1051,13 +1051,13 @@ TEST_CASE("meta/meta_states/method") {
|
||||
|
||||
CHECK_THROWS(mi.invoke(cl));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(cl)));
|
||||
CHECK(mi.invoke(std::move(cl)) == 12);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))) == 12);
|
||||
CHECK(mi.invoke(std::move(cl)).get_as<int>() == 12);
|
||||
CHECK(mi.invoke(std::move(std::as_const(cl))).get_as<int>() == 12);
|
||||
|
||||
CHECK_THROWS(mi.invoke(clv));
|
||||
CHECK_THROWS(mi.invoke(std::as_const(clv)));
|
||||
CHECK(mi.invoke(std::move(clv)) == 12);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))) == 12);
|
||||
CHECK(mi.invoke(std::move(clv)).get_as<int>() == 12);
|
||||
CHECK(mi.invoke(std::move(std::as_const(clv))).get_as<int>() == 12);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1117,25 +1117,25 @@ TEST_CASE("meta/meta_states/method") {
|
||||
{
|
||||
clazz cl;
|
||||
CHECK(mi.is_invocable_with<clazz&>());
|
||||
CHECK(mi.invoke(cl) == -1);
|
||||
CHECK(mi.invoke(cl).get_as<int>() == -1);
|
||||
}
|
||||
|
||||
{
|
||||
clazz cl;
|
||||
CHECK(mi.is_invocable_with<clazz*>());
|
||||
CHECK(mi.invoke(&cl) == -1);
|
||||
CHECK(mi.invoke(&cl).get_as<int>() == -1);
|
||||
}
|
||||
|
||||
{
|
||||
derived_clazz dcl;
|
||||
CHECK(mi.is_invocable_with<derived_clazz&>());
|
||||
CHECK(mi.invoke(dcl) == -2);
|
||||
CHECK(mi.invoke(dcl).get_as<int>() == -2);
|
||||
}
|
||||
|
||||
{
|
||||
derived_clazz dcl;
|
||||
CHECK(mi.is_invocable_with<derived_clazz*>());
|
||||
CHECK(mi.invoke(&dcl) == -2);
|
||||
CHECK(mi.invoke(&dcl).get_as<int>() == -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK(vm.get_type() == meta::resolve_type(&clazz_1::int_variable));
|
||||
CHECK(vm.get_name() == "int_variable");
|
||||
|
||||
CHECK(vm.get() == 1);
|
||||
CHECK(vm() == 1);
|
||||
CHECK(vm.get().get_as<int>() == 1);
|
||||
CHECK(vm().get_as<int>() == 1);
|
||||
|
||||
CHECK(vm.is_settable_with<int>());
|
||||
CHECK(vm.is_settable_with<int&&>());
|
||||
@@ -84,8 +84,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK_FALSE(vm.is_settable_with<const float&>());
|
||||
CHECK_FALSE(vm.is_settable_with(1.0));
|
||||
|
||||
vm.set(10); CHECK(vm.get() == 10);
|
||||
vm(11); CHECK(vm() == 11);
|
||||
vm.set(10); CHECK(vm.get().get_as<int>() == 10);
|
||||
vm(11); CHECK(vm().get_as<int>() == 11);
|
||||
}
|
||||
|
||||
SUBCASE("const int") {
|
||||
@@ -95,8 +95,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK(vm.get_type() == meta::resolve_type(&clazz_1::const_int_variable));
|
||||
CHECK(vm.get_name() == "const_int_variable");
|
||||
|
||||
CHECK(vm.get() == 2);
|
||||
CHECK(vm() == 2);
|
||||
CHECK(vm.get().get_as<int>() == 2);
|
||||
CHECK(vm().get_as<int>() == 2);
|
||||
|
||||
CHECK_FALSE(vm.is_settable_with<int>());
|
||||
CHECK_FALSE(vm.is_settable_with<int&&>());
|
||||
@@ -108,8 +108,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK_FALSE(vm.is_settable_with<const float&>());
|
||||
CHECK_FALSE(vm.is_settable_with(1.0));
|
||||
|
||||
CHECK_THROWS(vm.set(10)); CHECK(vm.get() == 2);
|
||||
CHECK_THROWS(vm(10)); CHECK(vm() == 2);
|
||||
CHECK_THROWS(vm.set(10)); CHECK(vm.get().get_as<int>() == 2);
|
||||
CHECK_THROWS(vm(10)); CHECK(vm().get_as<int>() == 2);
|
||||
}
|
||||
|
||||
SUBCASE("ref int") {
|
||||
@@ -119,8 +119,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK(vm.get_type() == meta::resolve_type(&clazz_1::ref_int_variable));
|
||||
CHECK(vm.get_name() == "ref_int_variable");
|
||||
|
||||
CHECK(vm.get() == 11);
|
||||
CHECK(vm() == 11);
|
||||
CHECK(vm.get().get_as<int>() == 11);
|
||||
CHECK(vm().get_as<int>() == 11);
|
||||
|
||||
CHECK(vm.is_settable_with<int>());
|
||||
CHECK(vm.is_settable_with<int&&>());
|
||||
@@ -132,8 +132,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK_FALSE(vm.is_settable_with<const float&>());
|
||||
CHECK_FALSE(vm.is_settable_with(1.0));
|
||||
|
||||
vm.set(20); CHECK(vm.get() == 20);
|
||||
vm(21); CHECK(vm() == 21);
|
||||
vm.set(20); CHECK(vm.get().get_as<int>() == 20);
|
||||
vm(21); CHECK(vm().get_as<int>() == 21);
|
||||
}
|
||||
|
||||
SUBCASE("const ref int") {
|
||||
@@ -143,8 +143,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK(vm.get_type() == meta::resolve_type(&clazz_1::const_ref_int_variable));
|
||||
CHECK(vm.get_name() == "const_ref_int_variable");
|
||||
|
||||
CHECK(vm.get() == 2);
|
||||
CHECK(vm() == 2);
|
||||
CHECK(vm.get().get_as<int>() == 2);
|
||||
CHECK(vm().get_as<int>() == 2);
|
||||
|
||||
CHECK_FALSE(vm.is_settable_with<int>());
|
||||
CHECK_FALSE(vm.is_settable_with<int&&>());
|
||||
@@ -156,8 +156,8 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
CHECK_FALSE(vm.is_settable_with<const float&>());
|
||||
CHECK_FALSE(vm.is_settable_with(1.0));
|
||||
|
||||
CHECK_THROWS(vm.set(10)); CHECK(vm.get() == 2);
|
||||
CHECK_THROWS(vm(11)); CHECK(vm() == 2);
|
||||
CHECK_THROWS(vm.set(10)); CHECK(vm.get().get_as<int>() == 2);
|
||||
CHECK_THROWS(vm(11)); CHECK(vm().get_as<int>() == 2);
|
||||
}
|
||||
|
||||
SUBCASE("unique_int_variable_as_ptr") {
|
||||
@@ -165,7 +165,7 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
REQUIRE(vm);
|
||||
|
||||
CHECK(vm.get().get_type() == meta::resolve_type<std::unique_ptr<int>*>());
|
||||
CHECK(vm.get() == std::addressof(clazz_1::unique_int_variable));
|
||||
CHECK(vm.get().get_as<std::unique_ptr<int>*>() == std::addressof(clazz_1::unique_int_variable));
|
||||
|
||||
{
|
||||
auto nv = std::make_unique<int>(11);
|
||||
@@ -206,7 +206,7 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
REQUIRE(vm);
|
||||
|
||||
CHECK(vm.get().get_type() == meta::resolve_type<const std::unique_ptr<int>*>());
|
||||
CHECK(vm.get() == std::addressof(clazz_1::const_unique_int_variable));
|
||||
CHECK(vm.get().get_as<const std::unique_ptr<int>*>() == std::addressof(clazz_1::const_unique_int_variable));
|
||||
|
||||
{
|
||||
auto nv = std::make_unique<int>(11);
|
||||
|
||||
@@ -89,8 +89,8 @@ TEST_CASE("meta/meta_types/enum_type") {
|
||||
{
|
||||
const meta::evalue green_value = color_type.get_evalue("green");
|
||||
REQUIRE(green_value);
|
||||
CHECK(green_value.get_value() == color::green);
|
||||
CHECK(green_value.get_underlying_value() == meta::detail::to_underlying(color::green));
|
||||
CHECK(green_value.get_value().get_as<color>() == color::green);
|
||||
CHECK(green_value.get_underlying_value().get_as<unsigned>() == meta::detail::to_underlying(color::green));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -106,8 +106,8 @@ TEST_CASE("meta/meta_types/enum_type") {
|
||||
{
|
||||
const meta::evalue green_value = ecolor_type.get_evalue("green");
|
||||
REQUIRE(green_value);
|
||||
CHECK(green_value.get_value() == ecolor_green);
|
||||
CHECK(green_value.get_underlying_value() == meta::detail::to_underlying(ecolor_green));
|
||||
CHECK(green_value.get_value().get_as<ecolor>() == ecolor_green);
|
||||
CHECK(green_value.get_underlying_value().get_as<int>() == meta::detail::to_underlying(ecolor_green));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -140,7 +140,7 @@ TEST_CASE("meta/meta_types/enum_type") {
|
||||
|
||||
{
|
||||
REQUIRE(color_type.name_to_value("blue"));
|
||||
CHECK(color_type.name_to_value("blue") == color::blue);
|
||||
CHECK(color_type.name_to_value("blue").get_as<color>() == color::blue);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -154,7 +154,7 @@ TEST_CASE("meta/meta_types/enum_type") {
|
||||
|
||||
{
|
||||
REQUIRE(ecolor_type.name_to_value("blue"));
|
||||
CHECK(ecolor_type.name_to_value("blue") == ecolor_blue);
|
||||
CHECK(ecolor_type.name_to_value("blue").get_as<ecolor>() == ecolor_blue);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -48,10 +48,10 @@ TEST_CASE("meta/meta_utilities/arg6") {
|
||||
CHECK(f.is_invocable_with<clazz&, int_member_t>());
|
||||
|
||||
CHECK(f.is_invocable_with(cl, &clazz::int_member));
|
||||
CHECK(f.invoke(cl, &clazz::int_member) == 42);
|
||||
CHECK(f.invoke(cl, &clazz::int_member).get_as<int>() == 42);
|
||||
|
||||
CHECK(f.is_invocable_with(meta::uvalue{cl}, meta::uvalue{&clazz::int_member}));
|
||||
CHECK(f.invoke(meta::uvalue{cl}, meta::uvalue{&clazz::int_member}) == 42);
|
||||
CHECK(f.invoke(meta::uvalue{cl}, meta::uvalue{&clazz::int_member}).get_as<int>() == 42);
|
||||
}
|
||||
|
||||
SUBCASE("int_method") {
|
||||
@@ -62,9 +62,9 @@ TEST_CASE("meta/meta_utilities/arg6") {
|
||||
CHECK(f.is_invocable_with<clazz&, int_method_t>());
|
||||
|
||||
CHECK(f.is_invocable_with(cl, &clazz::int_method));
|
||||
CHECK(f.invoke(cl, &clazz::int_method) == 42);
|
||||
CHECK(f.invoke(cl, &clazz::int_method).get_as<int>() == 42);
|
||||
|
||||
CHECK(f.is_invocable_with(meta::uvalue{cl}, meta::uvalue{&clazz::int_method}));
|
||||
CHECK(f.invoke(meta::uvalue{cl}, meta::uvalue{&clazz::int_method}) == 42);
|
||||
CHECK(f.invoke(meta::uvalue{cl}, meta::uvalue{&clazz::int_method}).get_as<int>() == 42);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace
|
||||
std::ignore = uarg{FromValue}.cast<ToType>();\
|
||||
\
|
||||
CHECK(f_state.is_invocable_with<decltype(FromValue)>());\
|
||||
CHECK(f_state.invoke(FromValue) == 1);\
|
||||
CHECK(f_state.invoke(FromValue).get_as<int>() == 1);\
|
||||
} else {\
|
||||
CHECK_FALSE(uarg{FromValue}.can_cast_to<ToType>());\
|
||||
CHECK_FALSE(uarg_base{type_list<decltype(FromValue)>{}}.can_cast_to<ToType>());\
|
||||
@@ -99,7 +99,7 @@ namespace
|
||||
if ( std::is_invocable_v<decltype(function_ptr), FromType> ) {\
|
||||
CHECK(f_state.is_invocable_with<FromType>());\
|
||||
CHECK(f_state.is_invocable_with(FromValue));\
|
||||
CHECK(f_state.invoke(FromValue) == 1);\
|
||||
CHECK(f_state.invoke(FromValue).get_as<int>() == 1);\
|
||||
} else {\
|
||||
CHECK_FALSE(f_state.is_invocable_with<FromType>());\
|
||||
CHECK_FALSE(f_state.is_invocable_with(FromValue));\
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace
|
||||
std::ignore = uinst{Inst}.cast<clazz Qualifiers>();\
|
||||
\
|
||||
CHECK(m_state.is_invocable_with<decltype(Inst)>());\
|
||||
CHECK(m_state.invoke(Inst) == 1);\
|
||||
CHECK(m_state.invoke(Inst).get_as<int>() == 1);\
|
||||
} else {\
|
||||
CHECK_FALSE(uinst{Inst}.can_cast_to<clazz Qualifiers>());\
|
||||
CHECK_FALSE(uinst_base{type_list<decltype(Inst)>{}}.can_cast_to<clazz Qualifiers>());\
|
||||
@@ -59,7 +59,7 @@ namespace
|
||||
if ( std::is_invocable_v<decltype(method_ptr), FromType> ) {\
|
||||
CHECK(m_state.is_invocable_with<FromType>());\
|
||||
CHECK(m_state.is_invocable_with(FromValue));\
|
||||
CHECK(m_state.invoke(FromValue) == 1);\
|
||||
CHECK(m_state.invoke(FromValue).get_as<int>() == 1);\
|
||||
} else {\
|
||||
CHECK_FALSE(m_state.is_invocable_with<FromType>());\
|
||||
CHECK_FALSE(m_state.is_invocable_with(FromValue));\
|
||||
|
||||
@@ -32,28 +32,28 @@ TEST_CASE("meta/meta_utilities/invoke") {
|
||||
REQUIRE((clazz_member && clazz_method && clazz_function));
|
||||
|
||||
{
|
||||
CHECK(meta::invoke(&clazz::function, 3) == 3);
|
||||
CHECK(meta::invoke(&clazz::function, meta::uvalue(3)) == 3);
|
||||
CHECK(meta::invoke(clazz_function, 3) == 3);
|
||||
CHECK(meta::invoke(clazz_function, meta::uvalue(3)) == 3);
|
||||
CHECK(meta::invoke(&clazz::function, 3).get_as<int>() == 3);
|
||||
CHECK(meta::invoke(&clazz::function, meta::uvalue{3}).get_as<int>() == 3);
|
||||
CHECK(meta::invoke(clazz_function, 3).get_as<int>() == 3);
|
||||
CHECK(meta::invoke(clazz_function, meta::uvalue{3}).get_as<int>() == 3);
|
||||
|
||||
CHECK(meta::is_invocable_with(clazz_function, 3));
|
||||
CHECK(meta::is_invocable_with(clazz_function, meta::uvalue(3)));
|
||||
CHECK(meta::is_invocable_with(clazz_function, meta::uvalue{3}));
|
||||
CHECK(meta::is_invocable_with<int>(clazz_function));
|
||||
|
||||
using function_t = decltype(&clazz::function);
|
||||
CHECK(meta::is_invocable_with<function_t>(3));
|
||||
CHECK(meta::is_invocable_with<function_t>(meta::uvalue(3)));
|
||||
CHECK(meta::is_invocable_with<function_t>(meta::uvalue{3}));
|
||||
CHECK(meta::is_invocable_with<function_t, int>());
|
||||
}
|
||||
|
||||
{
|
||||
clazz cl;
|
||||
|
||||
CHECK(meta::invoke(&clazz::member, cl) == 1);
|
||||
CHECK(meta::invoke(&clazz::member, meta::uvalue{cl}) == 1);
|
||||
CHECK(meta::invoke(clazz_member, cl) == 1);
|
||||
CHECK(meta::invoke(clazz_member, meta::uvalue{cl}) == 1);
|
||||
CHECK(meta::invoke(&clazz::member, cl).get_as<int>() == 1);
|
||||
CHECK(meta::invoke(&clazz::member, meta::uvalue{cl}).get_as<int>() == 1);
|
||||
CHECK(meta::invoke(clazz_member, cl).get_as<int>() == 1);
|
||||
CHECK(meta::invoke(clazz_member, meta::uvalue{cl}).get_as<int>() == 1);
|
||||
|
||||
CHECK(meta::is_invocable_with(clazz_member, cl));
|
||||
CHECK(meta::is_invocable_with(clazz_member, meta::uvalue{cl}));
|
||||
@@ -68,18 +68,18 @@ TEST_CASE("meta/meta_utilities/invoke") {
|
||||
{
|
||||
clazz cl;
|
||||
|
||||
CHECK(meta::invoke(&clazz::method, cl, 2) == 2);
|
||||
CHECK(meta::invoke(&clazz::method, meta::uvalue{cl}, meta::uvalue(2)) == 2);
|
||||
CHECK(meta::invoke(clazz_method, cl, 2) == 2);
|
||||
CHECK(meta::invoke(clazz_method, meta::uvalue{cl}, meta::uvalue(2)) == 2);
|
||||
CHECK(meta::invoke(&clazz::method, cl, 2).get_as<int>() == 2);
|
||||
CHECK(meta::invoke(&clazz::method, meta::uvalue{cl}, meta::uvalue{2}).get_as<int>() == 2);
|
||||
CHECK(meta::invoke(clazz_method, cl, 2).get_as<int>() == 2);
|
||||
CHECK(meta::invoke(clazz_method, meta::uvalue{cl}, meta::uvalue{2}).get_as<int>() == 2);
|
||||
|
||||
CHECK(meta::is_invocable_with(clazz_method, cl, 2));
|
||||
CHECK(meta::is_invocable_with(clazz_method, meta::uvalue{cl}, meta::uvalue(2)));
|
||||
CHECK(meta::is_invocable_with(clazz_method, meta::uvalue{cl}, meta::uvalue{2}));
|
||||
CHECK(meta::is_invocable_with<const clazz&, int>(clazz_method));
|
||||
|
||||
using method_t = decltype(&clazz::method);
|
||||
CHECK(meta::is_invocable_with<method_t>(cl, 2));
|
||||
CHECK(meta::is_invocable_with<method_t>(meta::uvalue{cl}, meta::uvalue(2)));
|
||||
CHECK(meta::is_invocable_with<method_t>(meta::uvalue{cl}, meta::uvalue{2}));
|
||||
CHECK(meta::is_invocable_with<method_t, const clazz&, int>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,23 +144,6 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
CHECK_THROWS(std::ignore = std::move(std::as_const(val)).get_as<int>());
|
||||
}
|
||||
|
||||
{
|
||||
CHECK_FALSE(1 < meta::uvalue{});
|
||||
CHECK(meta::uvalue{} < 1);
|
||||
}
|
||||
|
||||
{
|
||||
CHECK_FALSE(1 == meta::uvalue{});
|
||||
CHECK_FALSE(meta::uvalue{} == 1);
|
||||
}
|
||||
|
||||
{
|
||||
CHECK(1 != meta::uvalue{});
|
||||
CHECK(meta::uvalue{} != 1);
|
||||
}
|
||||
|
||||
CHECK_FALSE(meta::uvalue{} == 0);
|
||||
CHECK_FALSE(meta::uvalue{} == nullptr);
|
||||
CHECK(meta::uvalue{}.get_type() == meta::resolve_type<void>());
|
||||
}
|
||||
|
||||
@@ -179,7 +162,7 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).data()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).cdata()) == vr);
|
||||
|
||||
CHECK(val == ivec2{1,2});
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(std::as_const(val).get_as<ivec2>() == ivec2{1,2});
|
||||
@@ -212,7 +195,7 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).data()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).cdata()) == vr);
|
||||
|
||||
CHECK(val == ivec2{1,2});
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(std::as_const(val).get_as<ivec2>() == ivec2{1,2});
|
||||
@@ -239,7 +222,7 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
|
||||
CHECK(val.get_type() == meta::resolve_type<ivec2>());
|
||||
|
||||
CHECK(val == ivec2{1,2});
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(std::as_const(val).get_as<ivec2>() == ivec2{1,2});
|
||||
@@ -266,7 +249,7 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
|
||||
CHECK(val.get_type() == meta::resolve_type<ivec2>());
|
||||
|
||||
CHECK(val == ivec2{1,2});
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
|
||||
CHECK(val.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(std::as_const(val).get_as<ivec2>() == ivec2{1,2});
|
||||
@@ -291,7 +274,7 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
CHECK(ivec2::copy_constructor_counter == 0);
|
||||
|
||||
meta::uvalue val_dst{std::move(val_src)};
|
||||
CHECK(val_dst == ivec2{1,2});
|
||||
CHECK(val_dst.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(ivec2::move_constructor_counter == 2);
|
||||
CHECK(ivec2::copy_constructor_counter == 0);
|
||||
}
|
||||
@@ -303,11 +286,11 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
CHECK(ivec2::copy_constructor_counter == 1);
|
||||
|
||||
meta::uvalue val_dst{val_src};
|
||||
CHECK(val_dst == ivec2{1,2});
|
||||
CHECK(val_dst.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(ivec2::move_constructor_counter == 0);
|
||||
CHECK(ivec2::copy_constructor_counter == 2);
|
||||
|
||||
CHECK(val_src == ivec2{1,2});
|
||||
CHECK(val_src.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(val_src.data() != val_dst.data());
|
||||
}
|
||||
|
||||
@@ -315,10 +298,10 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
meta::uvalue val{10};
|
||||
|
||||
val = 20;
|
||||
CHECK(val == 20);
|
||||
CHECK(val.get_as<int>() == 20);
|
||||
|
||||
val = "hello"s;
|
||||
CHECK(val == "hello"s);
|
||||
CHECK(val.get_as<std::string>() == "hello"s);
|
||||
}
|
||||
|
||||
SUBCASE("value& operator=(value&&)") {
|
||||
@@ -330,12 +313,12 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
meta::uvalue val_dst{"hello"s};
|
||||
|
||||
val_dst = std::move(val_src1);
|
||||
CHECK(val_dst == "world"s);
|
||||
CHECK(val_dst.get_as<std::string>() == "world"s);
|
||||
CHECK(ivec2::move_constructor_counter == 1);
|
||||
CHECK(ivec2::copy_constructor_counter == 0);
|
||||
|
||||
val_dst = std::move(val_src2);
|
||||
CHECK(val_dst == ivec2{1,2});
|
||||
CHECK(val_dst.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(ivec2::move_constructor_counter == 3);
|
||||
CHECK(ivec2::copy_constructor_counter == 0);
|
||||
}
|
||||
@@ -349,16 +332,16 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
meta::uvalue val_dst{"hello"s};
|
||||
|
||||
val_dst = val_src1;
|
||||
CHECK(val_dst == "world"s);
|
||||
CHECK(val_dst.get_as<std::string>() == "world"s);
|
||||
CHECK(ivec2::move_constructor_counter == 1);
|
||||
CHECK(ivec2::copy_constructor_counter == 0);
|
||||
|
||||
val_dst = val_src2;
|
||||
CHECK(val_dst == ivec2{1,2});
|
||||
CHECK(val_dst.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(ivec2::move_constructor_counter == 2);
|
||||
CHECK(ivec2::copy_constructor_counter == 1);
|
||||
|
||||
CHECK(val_src2 == ivec2{1,2});
|
||||
CHECK(val_src2.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(val_src2.data() != val_dst.data());
|
||||
}
|
||||
|
||||
@@ -369,50 +352,14 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
CHECK(ivec2::copy_constructor_counter == 0);
|
||||
|
||||
val1.swap(val2);
|
||||
CHECK(val1 == ivec2{1,2});
|
||||
CHECK(val2 == "world"s);
|
||||
CHECK(val1.get_as<ivec2>() == ivec2{1,2});
|
||||
CHECK(val2.get_as<std::string>() == "world"s);
|
||||
CHECK(ivec2::move_constructor_counter == 2);
|
||||
CHECK(ivec2::copy_constructor_counter == 0);
|
||||
|
||||
swap(val1, val2);
|
||||
CHECK(val1 == "world"s);
|
||||
CHECK(val2 == ivec2{1,2});
|
||||
}
|
||||
|
||||
SUBCASE("ostream") {
|
||||
std::stringstream str_stream;
|
||||
str_stream << meta::uvalue{21} << " " << meta::uvalue{42};
|
||||
CHECK_THROWS((str_stream << meta::uvalue{ivec2{1,2}}));
|
||||
REQUIRE(str_stream.str() == "21 42");
|
||||
}
|
||||
|
||||
SUBCASE("istream") {
|
||||
std::stringstream str_stream{"21 42"};
|
||||
|
||||
meta::uvalue v{ivec2{1,2}};
|
||||
CHECK_THROWS(str_stream >> v);
|
||||
|
||||
v = meta::uvalue{0};
|
||||
str_stream >> v;
|
||||
CHECK(v == 21);
|
||||
str_stream >> v;
|
||||
CHECK(v == 42);
|
||||
}
|
||||
|
||||
SUBCASE("operator<") {
|
||||
CHECK(meta::uvalue{ivec2{1,2}} < ivec2{1,3});
|
||||
CHECK_FALSE(meta::uvalue{ivec2{1,3}} < ivec2{1,2});
|
||||
|
||||
CHECK(ivec2{1,2} < meta::uvalue{ivec2{1,3}});
|
||||
CHECK_FALSE(ivec2{1,3} < meta::uvalue{ivec2{1,2}});
|
||||
}
|
||||
|
||||
SUBCASE("operator==") {
|
||||
CHECK(meta::uvalue{ivec2{1,2}} == ivec2{1,2});
|
||||
CHECK_FALSE(meta::uvalue{ivec2{1,2}} == ivec2{1,3});
|
||||
|
||||
CHECK(ivec2{1,2} == meta::uvalue{ivec2{1,2}});
|
||||
CHECK_FALSE(ivec2{1,3} == meta::uvalue{ivec2{1,2}});
|
||||
CHECK(val1.get_as<std::string>() == "world"s);
|
||||
CHECK(val2.get_as<ivec2>() == ivec2{1,2});
|
||||
}
|
||||
|
||||
SUBCASE("deref") {
|
||||
@@ -468,7 +415,7 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
}
|
||||
{
|
||||
meta::uvalue v{std::make_shared<int>(42)};
|
||||
CHECK(*v == 42);
|
||||
CHECK((*v).get_as<int>() == 42);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -480,51 +427,51 @@ TEST_CASE("meta/meta_utilities/value/arrays") {
|
||||
int arr[3]{1,2,3};
|
||||
meta::uvalue v{arr};
|
||||
CHECK(v.get_type() == meta::resolve_type<int*>());
|
||||
CHECK(v[0] == 1);
|
||||
CHECK(v[1] == 2);
|
||||
CHECK(v[2] == 3);
|
||||
CHECK(v[0].get_as<int>() == 1);
|
||||
CHECK(v[1].get_as<int>() == 2);
|
||||
CHECK(v[2].get_as<int>() == 3);
|
||||
}
|
||||
|
||||
SUBCASE("const int[3]") {
|
||||
const int arr[3]{1,2,3};
|
||||
meta::uvalue v{arr};
|
||||
CHECK(v.get_type() == meta::resolve_type<const int*>());
|
||||
CHECK(v[0] == 1);
|
||||
CHECK(v[1] == 2);
|
||||
CHECK(v[2] == 3);
|
||||
CHECK(v[0].get_as<int>() == 1);
|
||||
CHECK(v[1].get_as<int>() == 2);
|
||||
CHECK(v[2].get_as<int>() == 3);
|
||||
}
|
||||
|
||||
SUBCASE("std::array") {
|
||||
meta::uvalue v{std::array{1,2,3}};
|
||||
CHECK(v.get_type() == meta::resolve_type<std::array<int, 3>>());
|
||||
CHECK(v[0] == 1);
|
||||
CHECK(v[1] == 2);
|
||||
CHECK(v[2] == 3);
|
||||
CHECK(v[0].get_as<int>() == 1);
|
||||
CHECK(v[1].get_as<int>() == 2);
|
||||
CHECK(v[2].get_as<int>() == 3);
|
||||
}
|
||||
|
||||
SUBCASE("std::string") {
|
||||
meta::uvalue v{std::string{"hi!"}};
|
||||
CHECK(v.get_type() == meta::resolve_type<std::string>());
|
||||
CHECK(v[0] == 'h');
|
||||
CHECK(v[1] == 'i');
|
||||
CHECK(v[2] == '!');
|
||||
CHECK(v[0].get_as<char>() == 'h');
|
||||
CHECK(v[1].get_as<char>() == 'i');
|
||||
CHECK(v[2].get_as<char>() == '!');
|
||||
}
|
||||
|
||||
SUBCASE("std::span") {
|
||||
std::vector arr{1,2,3};
|
||||
meta::uvalue v{std::span{arr}};
|
||||
CHECK(v.get_type() == meta::resolve_type<std::span<int>>());
|
||||
CHECK(v[0] == 1);
|
||||
CHECK(v[1] == 2);
|
||||
CHECK(v[2] == 3);
|
||||
CHECK(v[0].get_as<int>() == 1);
|
||||
CHECK(v[1].get_as<int>() == 2);
|
||||
CHECK(v[2].get_as<int>() == 3);
|
||||
}
|
||||
|
||||
SUBCASE("std::vector") {
|
||||
const meta::uvalue v{std::vector{1,2,3}};
|
||||
CHECK(v.get_type() == meta::resolve_type<std::vector<int>>());
|
||||
CHECK(v[0] == 1);
|
||||
CHECK(v[1] == 2);
|
||||
CHECK(v[2] == 3);
|
||||
CHECK(v[0].get_as<int>() == 1);
|
||||
CHECK(v[1].get_as<int>() == 2);
|
||||
CHECK(v[2].get_as<int>() == 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../meta_base.hpp"
|
||||
#include "../../meta_uvalue.hpp"
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
struct istream_traits;
|
||||
|
||||
template < typename T >
|
||||
concept has_istream_traits = requires(std::istream& is, T& v) {
|
||||
{ istream_traits<T>{}(is, v) } -> std::convertible_to<std::istream&>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
requires requires(std::istream& is, T& v) {
|
||||
{ is >> v } -> std::convertible_to<std::istream&>;
|
||||
}
|
||||
struct istream_traits<T> {
|
||||
std::istream& operator()(std::istream& is, T& v) const {
|
||||
return is >> v;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../meta_base.hpp"
|
||||
#include "../../meta_uvalue.hpp"
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
struct ostream_traits;
|
||||
|
||||
template < typename T >
|
||||
concept has_ostream_traits = requires(std::ostream& os, const T& v) {
|
||||
{ ostream_traits<T>{}(os, v) } -> std::convertible_to<std::ostream&>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename T >
|
||||
requires requires(std::ostream& os, const T& v) {
|
||||
{ os << v } -> std::convertible_to<std::ostream&>;
|
||||
}
|
||||
struct ostream_traits<T> {
|
||||
std::ostream& operator()(std::ostream& os, const T& v) const {
|
||||
return os << v;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
for ( auto&& [_, evalue] : data_->evalues ) {
|
||||
if ( evalue.get_value() == value ) {
|
||||
if ( evalue.get_value().get_as<Enum>() == value ) {
|
||||
return evalue.get_index().get_name();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace meta_hpp
|
||||
&& (!detail::is_in_place_type_v<Tp>)
|
||||
&& (std::is_copy_constructible_v<Tp>)
|
||||
// NOLINTNEXTLINE(*-forwarding-reference-overload)
|
||||
explicit uvalue(T&& val);
|
||||
uvalue(T&& val);
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::any_uvalue_kind<Tp>)
|
||||
@@ -100,9 +100,6 @@ namespace meta_hpp
|
||||
template < typename T >
|
||||
[[nodiscard]] auto try_get_as() const noexcept
|
||||
-> std::conditional_t<detail::pointer_kind<T>, T, const T*>;
|
||||
|
||||
friend std::istream& operator>>(std::istream& is, uvalue& v);
|
||||
friend std::ostream& operator<<(std::ostream& os, const uvalue& v);
|
||||
private:
|
||||
struct vtable_t;
|
||||
vtable_t* vtable_{};
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
|
||||
#include "../meta_detail/value_traits/deref_traits.hpp"
|
||||
#include "../meta_detail/value_traits/index_traits.hpp"
|
||||
#include "../meta_detail/value_traits/istream_traits.hpp"
|
||||
#include "../meta_detail/value_traits/ostream_traits.hpp"
|
||||
|
||||
#include "../meta_detail/value_utilities/utraits.hpp"
|
||||
|
||||
@@ -32,9 +30,6 @@ namespace meta_hpp
|
||||
uvalue (*const deref)(const storage_u& from);
|
||||
uvalue (*const index)(const storage_u& from, std::size_t);
|
||||
|
||||
std::istream& (*const istream)(std::istream& is, storage_u& to);
|
||||
std::ostream& (*const ostream)(std::ostream& os, const storage_u& from);
|
||||
|
||||
template < typename T >
|
||||
static T* buffer_cast(buffer_t& buffer) noexcept {
|
||||
// NOLINTNEXTLINE(*-reinterpret-cast)
|
||||
@@ -200,22 +195,6 @@ namespace meta_hpp
|
||||
detail::throw_exception_with("value type doesn't have value index traits");
|
||||
}
|
||||
},
|
||||
|
||||
.istream = +[]([[maybe_unused]] std::istream& is, [[maybe_unused]] storage_u& to) -> std::istream& {
|
||||
if constexpr ( detail::has_istream_traits<Tp> && !detail::pointer_kind<Tp> ) {
|
||||
return detail::istream_traits<Tp>{}(is, *storage_cast<Tp>(to));
|
||||
} else {
|
||||
detail::throw_exception_with("value type doesn't have value istream traits");
|
||||
}
|
||||
},
|
||||
|
||||
.ostream = +[]([[maybe_unused]] std::ostream& os, [[maybe_unused]] const storage_u& from) -> std::ostream& {
|
||||
if constexpr ( detail::has_ostream_traits<Tp> && !detail::pointer_kind<Tp> ) {
|
||||
return detail::ostream_traits<Tp>{}(os, *storage_cast<Tp>(from));
|
||||
} else {
|
||||
detail::throw_exception_with("value type doesn't have value ostream traits");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return &table;
|
||||
@@ -510,74 +489,3 @@ namespace meta_hpp
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator<(const uvalue& l, const T& r) {
|
||||
if ( !static_cast<bool>(l) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const any_type& l_type = l.get_type();
|
||||
const any_type& r_type = resolve_type<T>();
|
||||
|
||||
return (l_type < r_type) || (l_type == r_type && l.get_as<T>() < r);
|
||||
}
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator<(const T& l, const uvalue& r) {
|
||||
if ( !static_cast<bool>(r) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const any_type& l_type = resolve_type<T>();
|
||||
const any_type& r_type = r.get_type();
|
||||
|
||||
return (l_type < r_type) || (l_type == r_type && l < r.get_as<T>());
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator==(const uvalue& l, const T& r) {
|
||||
if ( !static_cast<bool>(l) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const any_type& l_type = l.get_type();
|
||||
const any_type& r_type = resolve_type<T>();
|
||||
|
||||
return l_type == r_type && l.get_as<T>() == r;
|
||||
}
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T> >
|
||||
requires (!detail::uvalue_kind<Tp>)
|
||||
[[nodiscard]] bool operator==(const T& l, const uvalue& r) {
|
||||
if ( !static_cast<bool>(r) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const any_type& l_type = resolve_type<T>();
|
||||
const any_type& r_type = r.get_type();
|
||||
|
||||
return l_type == r_type && l == r.get_as<T>();
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
inline std::istream& operator>>(std::istream& is, uvalue& v) {
|
||||
assert(v && "bad operator call"); // NOLINT
|
||||
return v.vtable_->istream(is, v.storage_);
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const uvalue& v) {
|
||||
assert(v && "bad operator call"); // NOLINT
|
||||
return v.vtable_->ostream(os, v.storage_);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user