From 8730e11d3c949d576c87f7c72f98354fe8cd21ea Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 18 Feb 2023 00:33:25 +0700 Subject: [PATCH] remove all get_as, try_invoke with uresult instead optional --- develop/manuals/meta_manuals/enum_manual.cpp | 4 +- .../manuals/meta_manuals/member_manual.cpp | 2 +- .../manuals/meta_manuals/scopes_manual.cpp | 4 +- .../manuals/meta_manuals/variable_manual.cpp | 4 +- develop/singles/headers/meta.hpp/meta_all.hpp | 313 +++++++----------- develop/untests/meta_states/ctor_tests.cpp | 24 +- develop/untests/meta_states/evalue_tests.cpp | 10 - .../untests/meta_states/function_tests.cpp | 32 +- develop/untests/meta_states/member_tests.cpp | 83 ++--- develop/untests/meta_states/method_tests.cpp | 272 +++++++-------- .../untests/meta_states/variable_tests.cpp | 62 ++-- .../untests/meta_types/enum_type_tests.cpp | 30 -- develop/untests/meta_utilities/arg_tests.cpp | 4 +- develop/untests/meta_utilities/inst_tests.cpp | 4 +- .../untests/meta_utilities/value5_tests.cpp | 169 ---------- headers/meta.hpp/meta_base/base.hpp | 1 - headers/meta.hpp/meta_states.hpp | 50 +-- headers/meta.hpp/meta_states/constructor.hpp | 32 +- headers/meta.hpp/meta_states/destructor.hpp | 22 ++ headers/meta.hpp/meta_states/evalue.hpp | 20 -- headers/meta.hpp/meta_states/function.hpp | 16 +- headers/meta.hpp/meta_states/member.hpp | 52 +-- headers/meta.hpp/meta_states/method.hpp | 8 - headers/meta.hpp/meta_states/variable.hpp | 34 +- headers/meta.hpp/meta_types.hpp | 6 - headers/meta.hpp/meta_types/enum_type.hpp | 12 +- headers/meta.hpp/meta_uvalue.hpp | 9 - headers/meta.hpp/meta_uvalue/uvalue.hpp | 51 --- 28 files changed, 469 insertions(+), 861 deletions(-) delete mode 100644 develop/untests/meta_utilities/value5_tests.cpp diff --git a/develop/manuals/meta_manuals/enum_manual.cpp b/develop/manuals/meta_manuals/enum_manual.cpp index 7d94bee..e83fd4b 100644 --- a/develop/manuals/meta_manuals/enum_manual.cpp +++ b/develop/manuals/meta_manuals/enum_manual.cpp @@ -41,7 +41,7 @@ TEST_CASE("meta/meta_manuals/enum/type") { for ( const meta::evalue& evalue : align_type.get_evalues() ) { fmt::print(" - {}/{}\n", evalue.get_name(), - evalue.get_underlying_value_as()); + evalue.get_underlying_value().get_as()); } // Output: @@ -63,5 +63,5 @@ TEST_CASE("meta/meta_manuals/enum/usage") { CHECK(align_type.value_to_name(e) == "center"); // ... and back again - CHECK(align_type.name_to_value_as("center") == e); + CHECK(align_type.name_to_value("center").get_as() == e); } diff --git a/develop/manuals/meta_manuals/member_manual.cpp b/develop/manuals/meta_manuals/member_manual.cpp index 3b69174..0d61fa9 100644 --- a/develop/manuals/meta_manuals/member_manual.cpp +++ b/develop/manuals/meta_manuals/member_manual.cpp @@ -65,7 +65,7 @@ TEST_CASE("meta/meta_manuals/member/usage") { CHECK(ivec2_x_typed_value == 42); // also, we can change the member value, of course - CHECK(ivec2_x.safe_set(v, 11)); + ivec2_x.set(v, 11); // checks the result of our manipulations CHECK(v.x == 11); diff --git a/develop/manuals/meta_manuals/scopes_manual.cpp b/develop/manuals/meta_manuals/scopes_manual.cpp index 17d9c9a..7bc627f 100644 --- a/develop/manuals/meta_manuals/scopes_manual.cpp +++ b/develop/manuals/meta_manuals/scopes_manual.cpp @@ -79,8 +79,8 @@ TEST_CASE("meta/meta_manuals/scopes/local") { const meta::variable unit3_variable = math_scope.get_variable("unit3"); // checks and uses found variables with functions - CHECK(unit2_variable.get_as() == ivec2{1,1}); - CHECK(unit3_variable.get_as() == ivec3{1,1,1}); + CHECK(unit2_variable.get().get_as() == ivec2{1,1}); + CHECK(unit3_variable.get().get_as() == ivec3{1,1,1}); CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()).get_as() == 2); CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()).get_as() == 3); } diff --git a/develop/manuals/meta_manuals/variable_manual.cpp b/develop/manuals/meta_manuals/variable_manual.cpp index 58f5258..9dbcbbf 100644 --- a/develop/manuals/meta_manuals/variable_manual.cpp +++ b/develop/manuals/meta_manuals/variable_manual.cpp @@ -40,14 +40,14 @@ TEST_CASE("meta/meta_manuals/variable/usage") { CHECK(pi_variable_value.get_as() == doctest::Approx(3.14).epsilon(0.01)); // we can change variable values, but only non-const - CHECK_FALSE(pi_variable.safe_set(6.0)); + CHECK_FALSE(pi_variable.try_set(6.0)); // prints all variables in the scope fmt::print("* {}\n", constants_scope.get_name()); for ( const meta::variable& variable : constants_scope.get_variables() ) { fmt::print(" - {} : {}\n", variable.get_name(), - variable.get_as()); + variable.get().get_as()); } // Output: diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index fa00100..2b2c3ab 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -2416,12 +2415,6 @@ namespace meta_hpp template < detail::enum_kind Enum > [[nodiscard]] std::string_view value_to_name(Enum value) const noexcept; [[nodiscard]] uvalue name_to_value(std::string_view name) const noexcept; - - template < detail::enum_kind Enum > - [[nodiscard]] Enum name_to_value_as(std::string_view name) const; - - template < detail::enum_kind Enum > - [[nodiscard]] std::optional safe_name_to_value_as(std::string_view name) const noexcept; }; class function_type final : public type_base { @@ -2964,15 +2957,6 @@ namespace meta_hpp [[nodiscard]] auto try_get_as() const noexcept // -> std::conditional_t, T, const T*>; - template < typename T > - [[nodiscard]] std::optional safe_get_as() &&; - - template < typename T > - [[nodiscard]] std::optional safe_get_as() &; - - template < typename T > - [[nodiscard]] std::optional safe_get_as() const&; - private: struct vtable_t; @@ -3411,13 +3395,13 @@ namespace meta_hpp [[nodiscard]] uvalue create(Args&&... args) const; template < typename... Args > - [[nodiscard]] std::optional safe_create(Args&&... args) const; + [[nodiscard]] uresult try_create(Args&&... args) const; template < typename... Args > uvalue create_at(void* mem, Args&&... args) const; template < typename... Args > - std::optional safe_create_at(void* mem, Args&&... args) const; + uresult try_create_at(void* mem, Args&&... args) const; template < typename... Args > [[nodiscard]] bool is_invocable_with() const noexcept; @@ -3438,8 +3422,13 @@ namespace meta_hpp template < typename Arg > void destroy(Arg&& arg) const; + template < typename Arg > + uresult try_destroy(Arg&& arg) const; + void destroy_at(void* mem) const; + uresult try_destroy_at(void* mem) const; + template < typename Arg > [[nodiscard]] bool is_invocable_with() const noexcept; @@ -3456,18 +3445,6 @@ namespace meta_hpp [[nodiscard]] const uvalue& get_value() const noexcept; [[nodiscard]] const uvalue& get_underlying_value() const noexcept; - - template < detail::enum_kind Enum > - [[nodiscard]] Enum get_value_as() const; - - template < detail::enum_kind Enum > - [[nodiscard]] std::optional safe_get_value_as() const noexcept; - - template < detail::number_kind Number > - [[nodiscard]] Number get_underlying_value_as() const; - - template < detail::number_kind Number > - [[nodiscard]] std::optional safe_get_underlying_value_as() const noexcept; }; class function final : public state_base { @@ -3481,7 +3458,7 @@ namespace meta_hpp uvalue invoke(Args&&... args) const; template < typename... Args > - std::optional safe_invoke(Args&&... args) const; + uresult try_invoke(Args&&... args) const; template < typename... Args > uvalue operator()(Args&&... args) const; @@ -3507,22 +3484,19 @@ namespace meta_hpp [[nodiscard]] uvalue get(Instance&& instance) const; template < typename Instance > - [[nodiscard]] std::optional safe_get(Instance&& instance) const; + [[nodiscard]] uresult try_get(Instance&& instance) const; template < typename T, typename Instance > [[nodiscard]] T get_as(Instance&& instance) const; - template < typename T, typename Instance > - [[nodiscard]] std::optional safe_get_as(Instance&& instance) const; + template < typename Instance > + [[nodiscard]] uvalue operator()(Instance&& instance) const; template < typename Instance, typename Value > void set(Instance&& instance, Value&& value) const; template < typename Instance, typename Value > - bool safe_set(Instance&& instance, Value&& value) const; - - template < typename Instance > - [[nodiscard]] uvalue operator()(Instance&& instance) const; + uresult try_set(Instance&& instance, Value&& value) const; template < typename Instance, typename Value > void operator()(Instance&& instance, Value&& value) const; @@ -3550,9 +3524,6 @@ namespace meta_hpp template < typename Instance, typename... Args > uvalue invoke(Instance&& instance, Args&&... args) const; - template < typename Instance, typename... Args > - std::optional safe_invoke(Instance&& instance, Args&&... args) const; - template < typename Instance, typename... Args > uresult try_invoke(Instance&& instance, Args&&... args) const; @@ -3599,22 +3570,15 @@ namespace meta_hpp [[nodiscard]] const std::string& get_name() const noexcept; [[nodiscard]] uvalue get() const; + [[nodiscard]] uresult try_get() const; - [[nodiscard]] std::optional safe_get() const; - - template < typename T > - [[nodiscard]] T get_as() const; - - template < typename T > - [[nodiscard]] std::optional safe_get_as() const; + [[nodiscard]] uvalue operator()() const; template < typename Value > void set(Value&& value) const; template < typename Value > - bool safe_set(Value&& value) const; - - [[nodiscard]] uvalue operator()() const; + uresult try_set(Value&& value) const; template < typename Value > void operator()(Value&& value) const; @@ -6067,11 +6031,19 @@ namespace meta_hpp } template < typename... Args > - std::optional function::safe_invoke(Args&&... args) const { - if ( is_invocable_with(std::forward(args)...) ) { - return invoke(std::forward(args)...); + uresult function::try_invoke(Args&&... args) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const std::array vargs{uarg_base{registry, std::forward(args)}...}; + if ( const uerror err = state_->invoke_error(vargs) ) { + return err; + } } - return std::nullopt; + + const std::array vargs{uarg{registry, std::forward(args)}...}; + return state_->invoke(vargs); } template < typename... Args > @@ -6561,21 +6533,24 @@ namespace meta_hpp } template < typename Instance > - std::optional member::safe_get(Instance&& instance) const { - if ( is_gettable_with(std::forward(instance)) ) { - return get(std::forward(instance)); + uresult member::try_get(Instance&& instance) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const uinst_base vinst{registry, std::forward(instance)}; + if ( const uerror err = state_->getter_error(vinst) ) { + return err; + } } - return std::nullopt; + + const uinst vinst{registry, std::forward(instance)}; + return state_->getter(vinst); } - template < typename T, typename Instance > - T member::get_as(Instance&& instance) const { - return get(std::forward(instance)).template get_as(); - } - - template < typename T, typename Instance > - std::optional member::safe_get_as(Instance&& instance) const { - return safe_get(std::forward(instance)).value_or(uvalue{}).template safe_get_as(); + template < typename Instance > + uvalue member::operator()(Instance&& instance) const { + return get(std::forward(instance)); } template < typename Instance, typename Value > @@ -6588,17 +6563,22 @@ namespace meta_hpp } template < typename Instance, typename Value > - bool member::safe_set(Instance&& instance, Value&& value) const { - if ( is_settable_with(std::forward(instance), std::forward(value)) ) { - set(std::forward(instance), std::forward(value)); - return true; - } - return false; - } + uresult member::try_set(Instance&& instance, Value&& value) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; - template < typename Instance > - uvalue member::operator()(Instance&& instance) const { - return get(std::forward(instance)); + { + const uinst_base vinst{registry, std::forward(instance)}; + const uarg_base vvalue{registry, std::forward(value)}; + if ( const uerror err = state_->setter_error(vinst, vvalue) ) { + return err; + } + } + + const uinst vinst{registry, std::forward(instance)}; + const uarg vvalue{registry, std::forward(value)}; + state_->setter(vinst, vvalue); + return uerror{error_code::no_error}; } template < typename Instance, typename Value > @@ -6828,14 +6808,6 @@ namespace meta_hpp return state_->invoke(vinst, vargs); } - template < typename Instance, typename... Args > - std::optional method::safe_invoke(Instance&& instance, Args&&... args) const { - if ( is_invocable_with(std::forward(instance), std::forward(args)...) ) { - return invoke(std::forward(instance), std::forward(args)...); - } - return std::nullopt; - } - template < typename Instance, typename... Args > uresult method::try_invoke(Instance&& instance, Args&&... args) const { using namespace detail; @@ -7244,11 +7216,19 @@ namespace meta_hpp } template < typename... Args > - std::optional constructor::safe_create(Args&&... args) const { - if ( is_invocable_with(std::forward(args)...) ) { - return create(std::forward(args)...); + uresult constructor::try_create(Args&&... args) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const std::array vargs{uarg_base{registry, type_list{}}...}; + if ( const uerror err = state_->create_error(vargs) ) { + return err; + } } - return std::nullopt; + + const std::array vargs{uarg{registry, std::forward(args)}...}; + return state_->create(vargs); } template < typename... Args > @@ -7260,11 +7240,19 @@ namespace meta_hpp } template < typename... Args > - std::optional constructor::safe_create_at(void* mem, Args&&... args) const { - if ( is_invocable_with(std::forward(args)...) ) { - return create_at(mem, std::forward(args)...); + uresult constructor::try_create_at(void* mem, Args&&... args) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const std::array vargs{uarg_base{registry, type_list{}}...}; + if ( const uerror err = state_->create_error(vargs) ) { + return err; + } } - return std::nullopt; + + const std::array vargs{uarg{registry, std::forward(args)}...}; + return state_->create_at(mem, vargs); } template < typename... Args > @@ -7404,10 +7392,32 @@ namespace meta_hpp return state_->destroy(varg); } + template < typename Arg > + uresult destructor::try_destroy(Arg&& arg) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const uarg_base varg{registry, std::forward(arg)}; + if ( const uerror err = state_->destroy_error(varg) ) { + return err; + } + } + + const uarg varg{registry, std::forward(arg)}; + state_->destroy(varg); + return uerror{error_code::no_error}; + } + inline void destructor::destroy_at(void* mem) const { state_->destroy_at(mem); } + inline uresult destructor::try_destroy_at(void* mem) const { + state_->destroy_at(mem); + return uerror{error_code::no_error}; + } + template < typename Arg > bool destructor::is_invocable_with() const noexcept { using namespace detail; @@ -7467,7 +7477,7 @@ namespace meta_hpp } for ( const evalue& evalue : data_->evalues ) { - if ( evalue.get_value_as() == value ) { + if ( evalue.get_value().get_as() == value ) { return evalue.get_name(); } } @@ -7482,16 +7492,6 @@ namespace meta_hpp return uvalue{}; } - - template < detail::enum_kind Enum > - Enum enum_type::name_to_value_as(std::string_view name) const { - return name_to_value(name).get_as(); - } - - template < detail::enum_kind Enum > - std::optional enum_type::safe_name_to_value_as(std::string_view name) const noexcept { - return name_to_value(name).safe_get_as(); - } } namespace meta_hpp::detail @@ -7527,26 +7527,6 @@ namespace meta_hpp inline const uvalue& evalue::get_underlying_value() const noexcept { return state_->underlying_value; } - - template < detail::enum_kind Enum > - Enum evalue::get_value_as() const { - return get_value().get_as(); - } - - template < detail::enum_kind Enum > - std::optional evalue::safe_get_value_as() const noexcept { - return get_value().safe_get_as(); - } - - template < detail::number_kind Number > - Number evalue::get_underlying_value_as() const { - return get_underlying_value().get_as(); - } - - template < detail::number_kind Number > - std::optional evalue::safe_get_underlying_value_as() const noexcept { - return get_underlying_value().safe_get_as(); - } } namespace meta_hpp::detail @@ -7699,18 +7679,12 @@ namespace meta_hpp return state_->getter(); } - inline std::optional variable::safe_get() const { + inline uresult variable::try_get() const { return state_->getter(); } - template < typename T > - T variable::get_as() const { - return get().template get_as(); - } - - template < typename T > - std::optional variable::safe_get_as() const { - return safe_get().value_or(uvalue{}).template safe_get_as(); + inline uvalue variable::operator()() const { + return get(); } template < typename Value > @@ -7722,16 +7696,20 @@ namespace meta_hpp } template < typename Value > - bool variable::safe_set(Value&& value) const { - if ( is_settable_with(std::forward(value)) ) { - set(std::forward(value)); - return true; - } - return false; - } + uresult variable::try_set(Value&& value) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; - inline uvalue variable::operator()() const { - return get(); + { + const uarg_base vvalue{registry, std::forward(value)}; + if ( const uerror err = state_->setter_error(vvalue) ) { + return err; + } + } + + const uarg vvalue{registry, std::forward(value)}; + state_->setter(vvalue); + return uerror{error_code::no_error}; } template < typename Value > @@ -9204,57 +9182,6 @@ namespace meta_hpp return nullptr; } - - template < typename T > - std::optional uvalue::safe_get_as() && { - static_assert(std::is_same_v>); - - if constexpr ( detail::pointer_kind ) { - if ( T ptr = try_get_as(); ptr || get_type().is_nullptr() ) { - return ptr; - } - } else { - if ( T* ptr = try_get_as() ) { - return std::move(*ptr); - } - } - - return std::nullopt; - } - - template < typename T > - std::optional uvalue::safe_get_as() & { - static_assert(std::is_same_v>); - - if constexpr ( detail::pointer_kind ) { - if ( T ptr = try_get_as(); ptr || get_type().is_nullptr() ) { - return ptr; - } - } else { - if ( T* ptr = try_get_as() ) { - return *ptr; - } - } - - return std::nullopt; - } - - template < typename T > - std::optional uvalue::safe_get_as() const& { - static_assert(std::is_same_v>); - - if constexpr ( detail::pointer_kind ) { - if ( T ptr = try_get_as(); ptr || get_type().is_nullptr() ) { - return ptr; - } - } else { - if ( const T* ptr = try_get_as() ) { - return *ptr; - } - } - - return std::nullopt; - } } namespace meta_hpp diff --git a/develop/untests/meta_states/ctor_tests.cpp b/develop/untests/meta_states/ctor_tests.cpp index 7b69590..211c92a 100644 --- a/develop/untests/meta_states/ctor_tests.cpp +++ b/develop/untests/meta_states/ctor_tests.cpp @@ -166,18 +166,18 @@ TEST_CASE("meta/meta_states/ctor/as_object") { const meta::constructor ctor = clazz_type.get_constructor_with(); REQUIRE(ctor); { - std::optional v{ctor.safe_create(42.0)}; - CHECK_FALSE(v); + meta::uresult r{ctor.try_create(42.0)}; + CHECK_FALSE(r); CHECK(clazz_t::constructor_counter == 0); } { - std::optional v{ctor.safe_create(42)}; - CHECK(v); + meta::uresult r{ctor.try_create(42)}; + CHECK(r); CHECK(clazz_t::constructor_counter == 1); - CHECK(v->get_type() == meta::resolve_type()); - CHECK(v->get_as().i == 42); + CHECK(r.get_value().get_type() == meta::resolve_type()); + CHECK(r.get_value().get_as().i == 42); } } @@ -202,18 +202,18 @@ TEST_CASE("meta/meta_states/ctor/as_object") { const meta::constructor ctor = clazz_type.get_constructor_with(); REQUIRE(ctor); { - std::optional v{ctor.safe_create_at(clazz_mem, 42.0)}; - CHECK_FALSE(v); + meta::uresult r{ctor.try_create_at(clazz_mem, 42.0)}; + CHECK_FALSE(r); CHECK(clazz_t::constructor_counter == 0); } { - std::optional v{ctor.safe_create_at(clazz_mem, 42)}; - CHECK(v); + meta::uresult r{ctor.try_create_at(clazz_mem, 42)}; + CHECK(r); CHECK(clazz_t::constructor_counter == 1); - CHECK(v->get_type() == meta::resolve_type()); - CHECK(v->get_as()->i == 42); + CHECK(r.get_value().get_type() == meta::resolve_type()); + CHECK(r.get_value().get_as()->i == 42); } } diff --git a/develop/untests/meta_states/evalue_tests.cpp b/develop/untests/meta_states/evalue_tests.cpp index a6b5b42..c938d59 100644 --- a/develop/untests/meta_states/evalue_tests.cpp +++ b/develop/untests/meta_states/evalue_tests.cpp @@ -57,19 +57,9 @@ TEST_CASE("meta/meta_states/evalue") { CHECK(evalue.get_name() == "green"); CHECK(evalue.get_value().get_as() == color::green); - CHECK(evalue.get_value_as() == color::green); CHECK(evalue.get_value().get_type() == color_type); CHECK(evalue.get_underlying_value().get_as() == meta::detail::to_underlying(color::green)); - CHECK(evalue.get_underlying_value_as() == meta::detail::to_underlying(color::green)); CHECK(evalue.get_underlying_value().get_type() == color_type.get_underlying_type()); - - CHECK_THROWS(std::ignore = evalue.get_value_as()); - CHECK_FALSE(evalue.safe_get_value_as()); - CHECK(evalue.safe_get_value_as() == color::green); - - CHECK_THROWS(std::ignore = evalue.get_underlying_value_as()); - CHECK_FALSE(evalue.safe_get_underlying_value_as()); - CHECK(evalue.safe_get_underlying_value_as() == meta::detail::to_underlying(color::green)); } } diff --git a/develop/untests/meta_states/function_tests.cpp b/develop/untests/meta_states/function_tests.cpp index 8fd3a42..a9d4ed9 100644 --- a/develop/untests/meta_states/function_tests.cpp +++ b/develop/untests/meta_states/function_tests.cpp @@ -82,11 +82,11 @@ TEST_CASE("meta/meta_states/function") { CHECK(func.is_invocable_with()); CHECK(func.is_invocable_with()); - CHECK_FALSE(func.safe_invoke()); - CHECK_FALSE(func.safe_invoke(42)); - CHECK_FALSE(func.safe_invoke(ivec2{}, 42)); - CHECK_FALSE(func.safe_invoke(42, ivec2{})); - CHECK_FALSE(func.safe_invoke(ivec2{}, ivec2{}, 42)); + CHECK_FALSE(func.try_invoke()); + CHECK_FALSE(func.try_invoke(42)); + CHECK_FALSE(func.try_invoke(ivec2{}, 42)); + CHECK_FALSE(func.try_invoke(42, ivec2{})); + CHECK_FALSE(func.try_invoke(ivec2{}, ivec2{}, 42)); CHECK(func.invoke(ivec2{1,2}, ivec2{3,4})); CHECK(func.invoke(ivec2{1,2}, ivec2{3,4}).get_as() == ivec2{4,6}); @@ -109,9 +109,9 @@ TEST_CASE("meta/meta_states/function") { CHECK(func.is_invocable_with()); CHECK(func.is_invocable_with()); - CHECK_FALSE(func.safe_invoke()); - CHECK_FALSE(func.safe_invoke(42)); - CHECK_FALSE(func.safe_invoke(ivec2{}, 42)); + CHECK_FALSE(func.try_invoke()); + CHECK_FALSE(func.try_invoke(42)); + CHECK_FALSE(func.try_invoke(ivec2{}, 42)); CHECK(func.invoke(ivec2{2,3})); CHECK(func.invoke(ivec2{2,3}).get_as() == 13); @@ -148,13 +148,13 @@ TEST_CASE("meta/meta_states/function") { CHECK(func1.invoke(bounded_arr).get_as() == 10); CHECK(func1.invoke(unbounded_arr).get_as() == 10); - CHECK_FALSE(func1.safe_invoke(bounded_const_arr)); - CHECK_FALSE(func1.safe_invoke(unbounded_const_arr)); + CHECK_FALSE(func1.try_invoke(bounded_const_arr)); + CHECK_FALSE(func1.try_invoke(unbounded_const_arr)); CHECK(func1.invoke(meta::uvalue{bounded_arr}).get_as() == 10); CHECK(func1.invoke(meta::uvalue{unbounded_arr}).get_as() == 10); - CHECK_FALSE(func1.safe_invoke(meta::uvalue{bounded_const_arr})); - CHECK_FALSE(func1.safe_invoke(meta::uvalue{unbounded_const_arr})); + CHECK_FALSE(func1.try_invoke(meta::uvalue{bounded_const_arr})); + CHECK_FALSE(func1.try_invoke(meta::uvalue{unbounded_const_arr})); static_assert(std::is_invocable_v); static_assert(std::is_invocable_v); @@ -173,13 +173,13 @@ TEST_CASE("meta/meta_states/function") { CHECK(func2.invoke(bounded_arr).get_as() == 10); CHECK(func2.invoke(unbounded_arr).get_as() == 10); - CHECK_FALSE(func2.safe_invoke(bounded_const_arr)); - CHECK_FALSE(func2.safe_invoke(unbounded_const_arr)); + CHECK_FALSE(func2.try_invoke(bounded_const_arr)); + CHECK_FALSE(func2.try_invoke(unbounded_const_arr)); CHECK(func2.invoke(meta::uvalue{bounded_arr}).get_as() == 10); CHECK(func2.invoke(meta::uvalue{unbounded_arr}).get_as() == 10); - CHECK_FALSE(func2.safe_invoke(meta::uvalue{bounded_const_arr})); - CHECK_FALSE(func2.safe_invoke(meta::uvalue{unbounded_const_arr})); + CHECK_FALSE(func2.try_invoke(meta::uvalue{bounded_const_arr})); + CHECK_FALSE(func2.try_invoke(meta::uvalue{unbounded_const_arr})); static_assert(std::is_invocable_v); static_assert(std::is_invocable_v); diff --git a/develop/untests/meta_states/member_tests.cpp b/develop/untests/meta_states/member_tests.cpp index 2b338ad..c001986 100644 --- a/develop/untests/meta_states/member_tests.cpp +++ b/develop/untests/meta_states/member_tests.cpp @@ -91,13 +91,6 @@ TEST_CASE("meta/meta_states/member") { CHECK(vm.get(std::move(v)).get_as() == 1); CHECK(vm.get(std::move(std::as_const(v))).get_as() == 1); - CHECK(vm.get_as(v) == 1); - CHECK(vm.get_as(&v) == 1); - CHECK(vm.get_as(std::as_const(v)) == 1); - CHECK(vm.get_as(&std::as_const(v)) == 1); - CHECK(vm.get_as(std::move(v)) == 1); - CHECK(vm.get_as(std::move(std::as_const(v))) == 1); - CHECK(vm(v).get_as() == 1); CHECK(vm(&v).get_as() == 1); CHECK(vm(std::as_const(v)).get_as() == 1); @@ -105,8 +98,8 @@ TEST_CASE("meta/meta_states/member") { CHECK(vm(std::move(v)).get_as() == 1); CHECK(vm(std::move(std::as_const(v))).get_as() == 1); - CHECK_FALSE(vm.safe_get(v2)); - CHECK_FALSE(vm.safe_get(&v2)); + CHECK_FALSE(vm.try_get(v2)); + CHECK_FALSE(vm.try_get(&v2)); } { @@ -148,19 +141,19 @@ TEST_CASE("meta/meta_states/member") { { vm.set(v, 10); CHECK(vm.get(v).get_as() == 10); vm.set(&v, 100); CHECK(vm.get(v).get_as() == 100); - CHECK_FALSE(vm.safe_set(std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 100); - CHECK_FALSE(vm.safe_set(&std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 100); + CHECK_FALSE(vm.try_set(std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 100); + CHECK_FALSE(vm.try_set(&std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 100); vm.set(std::move(v), 12); CHECK(vm.get(v).get_as() == 12); - CHECK_FALSE(vm.safe_set(std::move(std::as_const(v)), 13)); CHECK(vm.get(v).get_as() == 12); + CHECK_FALSE(vm.try_set(std::move(std::as_const(v)), 13)); CHECK(vm.get(v).get_as() == 12); vm(v, 13); CHECK(vm(v).get_as() == 13); vm(&v, 130); CHECK(vm(v).get_as() == 130); vm(std::move(v), 15); CHECK(vm(v).get_as() == 15); - CHECK_FALSE(vm.safe_set(v2, 17)); - CHECK_FALSE(vm.safe_set(&v2, 17)); + CHECK_FALSE(vm.try_set(v2, 17)); + CHECK_FALSE(vm.try_set(&v2, 17)); CHECK(vm(v).get_as() == 15); } } @@ -213,8 +206,8 @@ TEST_CASE("meta/meta_states/member") { CHECK(vm(std::move(v)).get_as() == 2); CHECK(vm(std::move(std::as_const(v))).get_as() == 2); - CHECK_FALSE(vm.safe_get(v2)); - CHECK_FALSE(vm.safe_get(&v2)); + CHECK_FALSE(vm.try_get(v2)); + CHECK_FALSE(vm.try_get(&v2)); } { @@ -250,15 +243,15 @@ TEST_CASE("meta/meta_states/member") { } { - CHECK_FALSE(vm.safe_set(v, 10)); CHECK(vm.get(v).get_as() == 2); - CHECK_FALSE(vm.safe_set(&v, 10)); CHECK(vm.get(v).get_as() == 2); - CHECK_FALSE(vm.safe_set(std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 2); - CHECK_FALSE(vm.safe_set(&std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 2); - CHECK_FALSE(vm.safe_set(std::move(v), 12)); CHECK(vm.get(v).get_as() == 2); - CHECK_FALSE(vm.safe_set(std::move(std::as_const(v)), 16)); CHECK(vm.get(v).get_as() == 2); + CHECK_FALSE(vm.try_set(v, 10)); CHECK(vm.get(v).get_as() == 2); + CHECK_FALSE(vm.try_set(&v, 10)); CHECK(vm.get(v).get_as() == 2); + CHECK_FALSE(vm.try_set(std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 2); + CHECK_FALSE(vm.try_set(&std::as_const(v), 11)); CHECK(vm.get(v).get_as() == 2); + CHECK_FALSE(vm.try_set(std::move(v), 12)); CHECK(vm.get(v).get_as() == 2); + CHECK_FALSE(vm.try_set(std::move(std::as_const(v)), 16)); CHECK(vm.get(v).get_as() == 2); - CHECK_FALSE(vm.safe_set(v2, 17)); - CHECK_FALSE(vm.safe_set(&v2, 17)); + CHECK_FALSE(vm.try_set(v2, 17)); + CHECK_FALSE(vm.try_set(&v2, 17)); CHECK(vm(v).get_as() == 2); } } @@ -273,13 +266,13 @@ TEST_CASE("meta/meta_states/member") { { clazz_1 v; CHECK(vm.get(v).get_type() == meta::resolve_type*>()); - CHECK(vm.get_as*>(v) == std::addressof(v.unique_int_member)); + CHECK(vm.get(v).get_as*>() == std::addressof(v.unique_int_member)); } { const clazz_1 v; CHECK(vm.get(v).get_type() == meta::resolve_type*>()); - CHECK(vm.get_as*>(v) == std::addressof(v.unique_int_member)); + CHECK(vm.get(v).get_as*>() == std::addressof(v.unique_int_member)); } } @@ -294,55 +287,41 @@ TEST_CASE("meta/meta_states/member") { clazz_1 v; using ref_t = std::reference_wrapper>; CHECK(vm.get(v).get_type() == meta::resolve_type()); - CHECK(vm.get_as(v).get() == v.unique_int_member); + CHECK(vm.get(v).get_as().get() == v.unique_int_member); } { const clazz_1 v; using ref_t = std::reference_wrapper>; CHECK(vm.get(v).get_type() == meta::resolve_type()); - CHECK(vm.get_as(v).get() == v.unique_int_member); + CHECK(vm.get(v).get_as().get() == v.unique_int_member); } } - SUBCASE("safe_get") { + SUBCASE("try_get") { meta::member vm = clazz_1_type.get_member("int_member"); REQUIRE(vm); clazz_1 v; clazz_2 v2; - CHECK(vm.safe_get(v)); - CHECK(vm.safe_get(v)->get_as() == 1); - CHECK_FALSE(vm.safe_get(v2)); + CHECK(vm.try_get(v)); + CHECK(vm.try_get(v).get_value().get_as() == 1); + CHECK_FALSE(vm.try_get(v2)); } - SUBCASE("safe_get_as") { + SUBCASE("try_set") { meta::member vm = clazz_1_type.get_member("int_member"); REQUIRE(vm); clazz_1 v; clazz_2 v2; - CHECK(vm.safe_get_as(v) == 1); - CHECK_FALSE(vm.safe_get_as(v)); + CHECK(vm.try_set(v, 10)); + CHECK(vm.get(v).get_as() == 10); - CHECK_FALSE(vm.safe_get_as(v2)); - CHECK_FALSE(vm.safe_get_as(v2)); - } - - SUBCASE("safe_set") { - meta::member vm = clazz_1_type.get_member("int_member"); - REQUIRE(vm); - - clazz_1 v; - clazz_2 v2; - - CHECK(vm.safe_set(v, 10)); - CHECK(vm.get_as(v) == 10); - - CHECK_FALSE(vm.safe_set(v, 20.0)); - CHECK_FALSE(vm.safe_set(v2, 20)); - CHECK(vm.get_as(v) == 10); + CHECK_FALSE(vm.try_set(v, 20.0)); + CHECK_FALSE(vm.try_set(v2, 20)); + CHECK(vm.get(v).get_as() == 10); } } diff --git a/develop/untests/meta_states/method_tests.cpp b/develop/untests/meta_states/method_tests.cpp index 7896505..4672eda 100644 --- a/develop/untests/meta_states/method_tests.cpp +++ b/develop/untests/meta_states/method_tests.cpp @@ -149,14 +149,14 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue clv{cl}; CHECK(mi.invoke(cl).get_as() == 1); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); CHECK(mi.invoke(std::move(cl)).get_as() == 1); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl)))); CHECK(mi.invoke(clv).get_as() == 1); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); CHECK(mi.invoke(std::move(clv)).get_as() == 1); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(clv)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(clv)))); } { @@ -178,15 +178,15 @@ TEST_CASE("meta/meta_states/method") { CHECK(mi.invoke(std::move(cl1v)).get_as() == 1); CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as() == 1); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(std::is_invocable_v); @@ -235,14 +235,14 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue clv{cl}; CHECK(mi.invoke(cl).get_as() == 2); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); CHECK(mi.invoke(std::move(cl)).get_as() == 2); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl)))); CHECK(mi.invoke(clv).get_as() == 2); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); CHECK(mi.invoke(std::move(clv)).get_as() == 2); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(clv)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(clv)))); } { @@ -264,15 +264,15 @@ TEST_CASE("meta/meta_states/method") { CHECK(mi.invoke(std::move(cl1v)).get_as() == 2); CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as() == 2); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(std::is_invocable_v); @@ -488,14 +488,14 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue clv{cl}; CHECK(mi.invoke(cl).get_as() == 5); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); - CHECK_FALSE(mi.safe_invoke(std::move(cl))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl)))); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(std::move(cl))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl)))); CHECK(mi.invoke(clv).get_as() == 5); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); - CHECK_FALSE(mi.safe_invoke(std::move(clv))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(clv)))); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(std::move(clv))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(clv)))); } { @@ -517,15 +517,15 @@ TEST_CASE("meta/meta_states/method") { CHECK(mi.invoke(std::move(cl1v)).get_as() == 5); CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as() == 5); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(std::is_invocable_v); @@ -569,14 +569,14 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue clv{cl}; CHECK(mi.invoke(cl).get_as() == 6); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); - CHECK_FALSE(mi.safe_invoke(std::move(cl))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl)))); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(std::move(cl))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl)))); CHECK(mi.invoke(clv).get_as() == 6); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); - CHECK_FALSE(mi.safe_invoke(std::move(clv))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(clv)))); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(std::move(clv))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(clv)))); } { @@ -598,15 +598,15 @@ TEST_CASE("meta/meta_states/method") { CHECK(mi.invoke(std::move(cl1v)).get_as() == 6); CHECK(mi.invoke(std::move(std::as_const(cl1v))).get_as() == 6); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(std::is_invocable_v); @@ -811,15 +811,15 @@ TEST_CASE("meta/meta_states/method") { derived_clazz cl; meta::uvalue clv{cl}; - CHECK_FALSE(mi.safe_invoke(cl)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(cl)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); CHECK(mi.invoke(std::move(cl)).get_as() == 9); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl)))); - CHECK_FALSE(mi.safe_invoke(clv)); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(clv)); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); CHECK(mi.invoke(std::move(clv)).get_as() == 9); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(clv)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(clv)))); } { @@ -831,25 +831,25 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue cl1v{cl1}; meta::uvalue cl2v{cl2}; - CHECK_FALSE(mi.safe_invoke(cl1)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1)))); + CHECK_FALSE(mi.try_invoke(cl1)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1)))); - CHECK_FALSE(mi.safe_invoke(cl1v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1v)))); + CHECK_FALSE(mi.try_invoke(cl1v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1v)))); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(!std::is_invocable_v); @@ -892,15 +892,15 @@ TEST_CASE("meta/meta_states/method") { derived_clazz cl; meta::uvalue clv{cl}; - CHECK_FALSE(mi.safe_invoke(cl)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(cl)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); CHECK(mi.invoke(std::move(cl)).get_as() == 10); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl)))); - CHECK_FALSE(mi.safe_invoke(clv)); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(clv)); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); CHECK(mi.invoke(std::move(clv)).get_as() == 10); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(clv)))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(clv)))); } { @@ -912,25 +912,25 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue cl1v{cl1}; meta::uvalue cl2v{cl2}; - CHECK_FALSE(mi.safe_invoke(cl1)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1)))); + CHECK_FALSE(mi.try_invoke(cl1)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1)))); - CHECK_FALSE(mi.safe_invoke(cl1v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1v)))); + CHECK_FALSE(mi.try_invoke(cl1v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1v)))); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(!std::is_invocable_v); @@ -973,13 +973,13 @@ TEST_CASE("meta/meta_states/method") { derived_clazz cl; meta::uvalue clv{cl}; - CHECK_FALSE(mi.safe_invoke(cl)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(cl)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); CHECK(mi.invoke(std::move(cl)).get_as() == 11); CHECK(mi.invoke(std::move(std::as_const(cl))).get_as() == 11); - CHECK_FALSE(mi.safe_invoke(clv)); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(clv)); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); CHECK(mi.invoke(std::move(clv)).get_as() == 11); CHECK(mi.invoke(std::move(std::as_const(clv))).get_as() == 11); } @@ -993,25 +993,25 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue cl1v{cl1}; meta::uvalue cl2v{cl2}; - CHECK_FALSE(mi.safe_invoke(cl1)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1)))); + CHECK_FALSE(mi.try_invoke(cl1)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1)))); - CHECK_FALSE(mi.safe_invoke(cl1v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1v)))); + CHECK_FALSE(mi.try_invoke(cl1v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1v)))); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(!std::is_invocable_v); @@ -1054,13 +1054,13 @@ TEST_CASE("meta/meta_states/method") { derived_clazz cl; meta::uvalue clv{cl}; - CHECK_FALSE(mi.safe_invoke(cl)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl))); + CHECK_FALSE(mi.try_invoke(cl)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl))); CHECK(mi.invoke(std::move(cl)).get_as() == 12); CHECK(mi.invoke(std::move(std::as_const(cl))).get_as() == 12); - CHECK_FALSE(mi.safe_invoke(clv)); - CHECK_FALSE(mi.safe_invoke(std::as_const(clv))); + CHECK_FALSE(mi.try_invoke(clv)); + CHECK_FALSE(mi.try_invoke(std::as_const(clv))); CHECK(mi.invoke(std::move(clv)).get_as() == 12); CHECK(mi.invoke(std::move(std::as_const(clv))).get_as() == 12); } @@ -1074,25 +1074,25 @@ TEST_CASE("meta/meta_states/method") { meta::uvalue cl1v{cl1}; meta::uvalue cl2v{cl2}; - CHECK_FALSE(mi.safe_invoke(cl1)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1)))); + CHECK_FALSE(mi.try_invoke(cl1)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(cl1))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1)))); - CHECK_FALSE(mi.safe_invoke(cl1v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl1v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl1v)))); + CHECK_FALSE(mi.try_invoke(cl1v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(cl1v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl1v)))); - CHECK_FALSE(mi.safe_invoke(cl2)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2)))); + CHECK_FALSE(mi.try_invoke(cl2)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(cl2))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2)))); - CHECK_FALSE(mi.safe_invoke(cl2v)); - CHECK_FALSE(mi.safe_invoke(std::as_const(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(cl2v))); - CHECK_FALSE(mi.safe_invoke(std::move(std::as_const(cl2v)))); + CHECK_FALSE(mi.try_invoke(cl2v)); + CHECK_FALSE(mi.try_invoke(std::as_const(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(cl2v))); + CHECK_FALSE(mi.try_invoke(std::move(std::as_const(cl2v)))); } static_assert(!std::is_invocable_v); diff --git a/develop/untests/meta_states/variable_tests.cpp b/develop/untests/meta_states/variable_tests.cpp index d28e2d1..4b491de 100644 --- a/develop/untests/meta_states/variable_tests.cpp +++ b/develop/untests/meta_states/variable_tests.cpp @@ -87,7 +87,7 @@ 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_as() == 1); + CHECK(vm.get().get_as() == 1); CHECK(vm().get_as() == 1); CHECK(vm.is_settable_with()); @@ -100,7 +100,7 @@ TEST_CASE("meta/meta_states/variable") { CHECK_FALSE(vm.is_settable_with()); CHECK_FALSE(vm.is_settable_with(1.0)); - vm.set(10); CHECK(vm.get_as() == 10); + vm.set(10); CHECK(vm.get().get_as() == 10); vm(11); CHECK(vm().get_as() == 11); } @@ -111,7 +111,7 @@ 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_as() == 2); + CHECK(vm.get().get_as() == 2); CHECK(vm().get_as() == 2); CHECK_FALSE(vm.is_settable_with()); @@ -124,7 +124,7 @@ TEST_CASE("meta/meta_states/variable") { CHECK_FALSE(vm.is_settable_with()); CHECK_FALSE(vm.is_settable_with(1.0)); - CHECK_FALSE(vm.safe_set(10)); CHECK(vm.get_as() == 2); + CHECK_FALSE(vm.try_set(10)); CHECK(vm.get().get_as() == 2); } SUBCASE("ref int") { @@ -134,7 +134,7 @@ 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_as() == 1); + CHECK(vm.get().get_as() == 1); CHECK(vm().get_as() == 1); CHECK(vm.is_settable_with()); @@ -147,7 +147,7 @@ TEST_CASE("meta/meta_states/variable") { CHECK_FALSE(vm.is_settable_with()); CHECK_FALSE(vm.is_settable_with(1.0)); - vm.set(20); CHECK(vm.get_as() == 20); + vm.set(20); CHECK(vm.get().get_as() == 20); vm(21); CHECK(vm().get_as() == 21); } @@ -158,7 +158,7 @@ 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_as() == 2); + CHECK(vm.get().get_as() == 2); CHECK(vm().get_as() == 2); CHECK_FALSE(vm.is_settable_with()); @@ -171,7 +171,7 @@ TEST_CASE("meta/meta_states/variable") { CHECK_FALSE(vm.is_settable_with()); CHECK_FALSE(vm.is_settable_with(1.0)); - CHECK_FALSE(vm.safe_set(10)); CHECK(vm.get_as() == 2); + CHECK_FALSE(vm.try_set(10)); CHECK(vm.get().get_as() == 2); } SUBCASE("unique_int_variable_as_ptr") { @@ -179,7 +179,7 @@ TEST_CASE("meta/meta_states/variable") { REQUIRE(vm); CHECK(vm.get().get_type() == meta::resolve_type()); - CHECK(vm.get_as() == std::addressof(clazz_1::unique_int_variable)); + CHECK(vm.get().get_as() == std::addressof(clazz_1::unique_int_variable)); { unique_int nv{11}; @@ -189,7 +189,7 @@ TEST_CASE("meta/meta_states/variable") { { unique_int nv{12}; - CHECK_FALSE(vm.safe_set(nv)); + CHECK_FALSE(vm.try_set(nv)); CHECK(clazz_1::unique_int_variable.i == 11); } } @@ -200,7 +200,7 @@ TEST_CASE("meta/meta_states/variable") { using ref_t = std::reference_wrapper; CHECK(vm.get().get_type() == meta::resolve_type()); - CHECK(&vm.get_as().get() == &clazz_1::unique_int_variable); + CHECK(&vm.get().get_as().get() == &clazz_1::unique_int_variable); { unique_int nv{13}; @@ -210,7 +210,7 @@ TEST_CASE("meta/meta_states/variable") { { unique_int nv{14}; - CHECK_FALSE(vm.safe_set(nv)); + CHECK_FALSE(vm.try_set(nv)); CHECK(clazz_1::unique_int_variable.i == 13); } } @@ -220,12 +220,12 @@ TEST_CASE("meta/meta_states/variable") { REQUIRE(vm); CHECK(vm.get().get_type() == meta::resolve_type()); - CHECK(vm.get_as() == std::addressof(clazz_1::const_unique_int_variable)); + CHECK(vm.get().get_as() == std::addressof(clazz_1::const_unique_int_variable)); { unique_int nv{11}; - CHECK_FALSE(vm.safe_set(nv)); - CHECK_FALSE(vm.safe_set(std::move(nv))); + CHECK_FALSE(vm.try_set(nv)); + CHECK_FALSE(vm.try_set(std::move(nv))); CHECK(clazz_1::const_unique_int_variable.i == 42); } } @@ -236,40 +236,24 @@ TEST_CASE("meta/meta_states/variable") { using ref_t = std::reference_wrapper; CHECK(vm.get().get_type() == meta::resolve_type()); - CHECK(&vm.get_as().get() == &clazz_1::const_unique_int_variable); + CHECK(&vm.get().get_as().get() == &clazz_1::const_unique_int_variable); { unique_int nv{12}; - CHECK_FALSE(vm.safe_set(nv)); - CHECK_FALSE(vm.safe_set(std::move(nv))); + CHECK_FALSE(vm.try_set(nv)); + CHECK_FALSE(vm.try_set(std::move(nv))); CHECK(clazz_1::const_unique_int_variable.i == 42); } } - SUBCASE("safe_get") { + SUBCASE("try_set") { meta::variable vm = clazz_1_type.get_variable("int_variable"); REQUIRE(vm); - CHECK(vm.safe_get()); - CHECK(vm.safe_get()->get_as() == 1); - } + CHECK(vm.try_set(10)); + CHECK(vm.get().get_as() == 10); - SUBCASE("safe_get_as") { - meta::variable vm = clazz_1_type.get_variable("int_variable"); - REQUIRE(vm); - - CHECK(vm.safe_get_as() == 1); - CHECK_FALSE(vm.safe_get_as()); - } - - SUBCASE("safe_set") { - meta::variable vm = clazz_1_type.get_variable("int_variable"); - REQUIRE(vm); - - CHECK(vm.safe_set(10)); - CHECK(vm.get_as() == 10); - - CHECK_FALSE(vm.safe_set(unique_int{})); - CHECK(vm.get_as() == 10); + CHECK_FALSE(vm.try_set(unique_int{})); + CHECK(vm.get().get_as() == 10); } } diff --git a/develop/untests/meta_types/enum_type_tests.cpp b/develop/untests/meta_types/enum_type_tests.cpp index 6aa5faa..b6a8c7a 100644 --- a/develop/untests/meta_types/enum_type_tests.cpp +++ b/develop/untests/meta_types/enum_type_tests.cpp @@ -92,10 +92,7 @@ TEST_CASE("meta/meta_types/enum_type") { REQUIRE(green_value); CHECK(green_value.get_value().get_as() == color::green); - CHECK(green_value.get_value_as() == color::green); - CHECK(green_value.get_underlying_value().get_as() == meta::detail::to_underlying(color::green)); - CHECK(green_value.get_underlying_value_as() == meta::detail::to_underlying(color::green)); } { @@ -113,10 +110,7 @@ TEST_CASE("meta/meta_types/enum_type") { REQUIRE(green_value); CHECK(green_value.get_value().get_as() == ecolor_green); - CHECK(green_value.get_value_as() == ecolor_green); - CHECK(green_value.get_underlying_value().get_as() == meta::detail::to_underlying(ecolor_green)); - CHECK(green_value.get_underlying_value_as() == meta::detail::to_underlying(ecolor_green)); } { @@ -150,22 +144,10 @@ TEST_CASE("meta/meta_types/enum_type") { { REQUIRE(color_type.name_to_value("blue")); CHECK(color_type.name_to_value("blue").get_as() == color::blue); - CHECK(color_type.name_to_value_as("blue") == color::blue); - CHECK_THROWS(std::ignore = color_type.name_to_value_as("blue")); } { REQUIRE_FALSE(color_type.name_to_value("yellow")); - CHECK_THROWS(std::ignore = color_type.name_to_value_as("yellow")); - CHECK_THROWS(std::ignore = color_type.name_to_value_as("yellow")); - } - - { - REQUIRE(color_type.safe_name_to_value_as("blue")); - CHECK(color_type.safe_name_to_value_as("blue") == color::blue); - - CHECK_FALSE(color_type.safe_name_to_value_as("blue")); - CHECK_FALSE(color_type.safe_name_to_value_as("yellow")); } } @@ -176,22 +158,10 @@ TEST_CASE("meta/meta_types/enum_type") { { REQUIRE(ecolor_type.name_to_value("blue")); CHECK(ecolor_type.name_to_value("blue").get_as() == ecolor_blue); - CHECK(ecolor_type.name_to_value_as("blue") == ecolor_blue); - CHECK_THROWS(std::ignore = ecolor_type.name_to_value_as("blue")); } { REQUIRE_FALSE(ecolor_type.name_to_value("yellow")); - CHECK_THROWS(std::ignore = ecolor_type.name_to_value_as("yellow")); - CHECK_THROWS(std::ignore = ecolor_type.name_to_value_as("yellow")); - } - - { - REQUIRE(ecolor_type.safe_name_to_value_as("blue")); - CHECK(ecolor_type.safe_name_to_value_as("blue") == ecolor_blue); - - CHECK_FALSE(ecolor_type.safe_name_to_value_as("blue")); - CHECK_FALSE(ecolor_type.safe_name_to_value_as("yellow")); } } } diff --git a/develop/untests/meta_utilities/arg_tests.cpp b/develop/untests/meta_utilities/arg_tests.cpp index d7d71fc..9a9ab08 100644 --- a/develop/untests/meta_utilities/arg_tests.cpp +++ b/develop/untests/meta_utilities/arg_tests.cpp @@ -86,7 +86,7 @@ namespace /*CHECK_THROWS(std::ignore = uarg{r, FromValue}.cast(r));*/\ \ CHECK_FALSE(f_state.is_invocable_with());\ - CHECK_FALSE(f_state.safe_invoke(FromValue));\ + CHECK_FALSE(f_state.try_invoke(FromValue));\ }\ } @@ -104,7 +104,7 @@ namespace } else {\ CHECK_FALSE(f_state.is_invocable_with());\ CHECK_FALSE(f_state.is_invocable_with(FromValue));\ - CHECK_FALSE(f_state.safe_invoke(FromValue));\ + CHECK_FALSE(f_state.try_invoke(FromValue));\ }\ } diff --git a/develop/untests/meta_utilities/inst_tests.cpp b/develop/untests/meta_utilities/inst_tests.cpp index c6af82e..6b534e6 100644 --- a/develop/untests/meta_utilities/inst_tests.cpp +++ b/develop/untests/meta_utilities/inst_tests.cpp @@ -46,7 +46,7 @@ namespace /*CHECK_THROWS(std::ignore = uinst{r, Inst}.cast(r));*/\ \ CHECK_FALSE(m_state.is_invocable_with());\ - CHECK_FALSE(m_state.safe_invoke(Inst));\ + CHECK_FALSE(m_state.try_invoke(Inst));\ }\ } @@ -64,7 +64,7 @@ namespace } else {\ CHECK_FALSE(m_state.is_invocable_with());\ CHECK_FALSE(m_state.is_invocable_with(FromValue));\ - CHECK_FALSE(m_state.safe_invoke(FromValue));\ + CHECK_FALSE(m_state.try_invoke(FromValue));\ }\ } diff --git a/develop/untests/meta_utilities/value5_tests.cpp b/develop/untests/meta_utilities/value5_tests.cpp deleted file mode 100644 index e43697b..0000000 --- a/develop/untests/meta_utilities/value5_tests.cpp +++ /dev/null @@ -1,169 +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) - ******************************************************************************/ - -#include -#include - -namespace -{ - struct ivec2 final { - int x{}; - int y{}; - - ivec2(int nx, int ny) - : x{nx}, y{ny} {} - - ivec2(ivec2&& other) noexcept - : x{other.x} - , y{other.y} { - other.x = 0; - other.y = 0; - } - - ivec2(const ivec2& other) - : x{other.x} - , y{other.y} {} - }; - - bool operator==(const ivec2& l, const ivec2& r) noexcept { - return l.x == r.x && l.y == r.y; - } -} - -TEST_CASE("meta/meta_utilities/value5/safe_get_as") { - namespace meta = meta_hpp; - - SUBCASE("&/val") { - { - meta::uvalue v{ivec2{1,2}}; - - REQUIRE(v.safe_get_as()); - CHECK(v.safe_get_as() == ivec2{1,2}); - - CHECK_FALSE(v.safe_get_as()); - } - { - const meta::uvalue v{ivec2{1,2}}; - - REQUIRE(v.safe_get_as()); - CHECK(v.safe_get_as() == ivec2{1,2}); - - CHECK_FALSE(v.safe_get_as()); - } - } - - SUBCASE("&&/val") { - { - meta::uvalue v{ivec2{1,2}}; - const ivec2 v2 = *std::move(v).safe_get_as(); - CHECK(v2 == ivec2{1,2}); - CHECK(v.get_as() == ivec2{0,0}); - } - { - meta::uvalue v{ivec2{1,2}}; - CHECK_FALSE(std::move(v).safe_get_as()); - CHECK(v.get_as() == ivec2{1,2}); - } - } - - SUBCASE("&/ptr") { - { - ivec2 v{1,2}; - meta::uvalue v2{&v}; - - REQUIRE(v2.safe_get_as()); - REQUIRE(*v2.safe_get_as()); - CHECK(v2.safe_get_as() == &v); - - REQUIRE(v2.safe_get_as()); - REQUIRE(*v2.safe_get_as()); - CHECK(v2.safe_get_as() == &v); - - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - } - { - ivec2 v{1,2}; - const meta::uvalue v2{&v}; - - REQUIRE(v2.safe_get_as()); - REQUIRE(*v2.safe_get_as()); - CHECK(v2.safe_get_as() == &v); - - REQUIRE(v2.safe_get_as()); - REQUIRE(*v2.safe_get_as()); - CHECK(v2.safe_get_as() == &v); - - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - } - } - - SUBCASE("&/const_ptr") { - { - const ivec2 v{1,2}; - meta::uvalue v2{&v}; - - CHECK_FALSE(v2.safe_get_as()); - - REQUIRE(v2.safe_get_as()); - REQUIRE(*v2.safe_get_as()); - CHECK(v2.safe_get_as() == &v); - - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - } - { - const ivec2 v{1,2}; - const meta::uvalue v2{&v}; - - CHECK_FALSE(v2.safe_get_as()); - - REQUIRE(v2.safe_get_as()); - REQUIRE(*v2.safe_get_as()); - CHECK(v2.safe_get_as() == &v); - - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - CHECK_FALSE(v2.safe_get_as()); - } - } - - SUBCASE("&&/ptr") { - { - ivec2 v{1,2}; - meta::uvalue v2{&v}; - REQUIRE(std::move(v2).safe_get_as()); - CHECK(std::move(v2).safe_get_as() == &v); - } - { - ivec2 v{1,2}; - const meta::uvalue v2{&v}; - REQUIRE(std::move(v2).safe_get_as()); - CHECK(std::move(v2).safe_get_as() == &v); - } - } - - SUBCASE("&&/const ptr") { - { - const ivec2 v{1,2}; - meta::uvalue v2{&v}; - CHECK_FALSE(std::move(v2).safe_get_as()); - REQUIRE(std::move(v2).safe_get_as()); - CHECK(std::move(v2).safe_get_as() == &v); - } - { - const ivec2 v{1,2}; - const meta::uvalue v2{&v}; - CHECK_FALSE(std::move(v2).safe_get_as()); - REQUIRE(std::move(v2).safe_get_as()); - CHECK(std::move(v2).safe_get_as() == &v); - } - } -} diff --git a/headers/meta.hpp/meta_base/base.hpp b/headers/meta.hpp/meta_base/base.hpp index 134450e..07c9f06 100644 --- a/headers/meta.hpp/meta_base/base.hpp +++ b/headers/meta.hpp/meta_base/base.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index a11f35e..eabbf77 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -178,13 +178,13 @@ namespace meta_hpp [[nodiscard]] uvalue create(Args&&... args) const; template < typename... Args > - [[nodiscard]] std::optional safe_create(Args&&... args) const; + [[nodiscard]] uresult try_create(Args&&... args) const; template < typename... Args > uvalue create_at(void* mem, Args&&... args) const; template < typename... Args > - std::optional safe_create_at(void* mem, Args&&... args) const; + uresult try_create_at(void* mem, Args&&... args) const; template < typename... Args > [[nodiscard]] bool is_invocable_with() const noexcept; @@ -205,8 +205,13 @@ namespace meta_hpp template < typename Arg > void destroy(Arg&& arg) const; + template < typename Arg > + uresult try_destroy(Arg&& arg) const; + void destroy_at(void* mem) const; + uresult try_destroy_at(void* mem) const; + template < typename Arg > [[nodiscard]] bool is_invocable_with() const noexcept; @@ -223,18 +228,6 @@ namespace meta_hpp [[nodiscard]] const uvalue& get_value() const noexcept; [[nodiscard]] const uvalue& get_underlying_value() const noexcept; - - template < detail::enum_kind Enum > - [[nodiscard]] Enum get_value_as() const; - - template < detail::enum_kind Enum > - [[nodiscard]] std::optional safe_get_value_as() const noexcept; - - template < detail::number_kind Number > - [[nodiscard]] Number get_underlying_value_as() const; - - template < detail::number_kind Number > - [[nodiscard]] std::optional safe_get_underlying_value_as() const noexcept; }; class function final : public state_base { @@ -248,7 +241,7 @@ namespace meta_hpp uvalue invoke(Args&&... args) const; template < typename... Args > - std::optional safe_invoke(Args&&... args) const; + uresult try_invoke(Args&&... args) const; template < typename... Args > uvalue operator()(Args&&... args) const; @@ -274,22 +267,19 @@ namespace meta_hpp [[nodiscard]] uvalue get(Instance&& instance) const; template < typename Instance > - [[nodiscard]] std::optional safe_get(Instance&& instance) const; + [[nodiscard]] uresult try_get(Instance&& instance) const; template < typename T, typename Instance > [[nodiscard]] T get_as(Instance&& instance) const; - template < typename T, typename Instance > - [[nodiscard]] std::optional safe_get_as(Instance&& instance) const; + template < typename Instance > + [[nodiscard]] uvalue operator()(Instance&& instance) const; template < typename Instance, typename Value > void set(Instance&& instance, Value&& value) const; template < typename Instance, typename Value > - bool safe_set(Instance&& instance, Value&& value) const; - - template < typename Instance > - [[nodiscard]] uvalue operator()(Instance&& instance) const; + uresult try_set(Instance&& instance, Value&& value) const; template < typename Instance, typename Value > void operator()(Instance&& instance, Value&& value) const; @@ -317,9 +307,6 @@ namespace meta_hpp template < typename Instance, typename... Args > uvalue invoke(Instance&& instance, Args&&... args) const; - template < typename Instance, typename... Args > - std::optional safe_invoke(Instance&& instance, Args&&... args) const; - template < typename Instance, typename... Args > uresult try_invoke(Instance&& instance, Args&&... args) const; @@ -366,22 +353,15 @@ namespace meta_hpp [[nodiscard]] const std::string& get_name() const noexcept; [[nodiscard]] uvalue get() const; + [[nodiscard]] uresult try_get() const; - [[nodiscard]] std::optional safe_get() const; - - template < typename T > - [[nodiscard]] T get_as() const; - - template < typename T > - [[nodiscard]] std::optional safe_get_as() const; + [[nodiscard]] uvalue operator()() const; template < typename Value > void set(Value&& value) const; template < typename Value > - bool safe_set(Value&& value) const; - - [[nodiscard]] uvalue operator()() const; + uresult try_set(Value&& value) const; template < typename Value > void operator()(Value&& value) const; diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 8dd7560..182413b 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -168,11 +168,19 @@ namespace meta_hpp } template < typename... Args > - std::optional constructor::safe_create(Args&&... args) const { - if ( is_invocable_with(std::forward(args)...) ) { - return create(std::forward(args)...); + uresult constructor::try_create(Args&&... args) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const std::array vargs{uarg_base{registry, type_list{}}...}; + if ( const uerror err = state_->create_error(vargs) ) { + return err; + } } - return std::nullopt; + + const std::array vargs{uarg{registry, std::forward(args)}...}; + return state_->create(vargs); } template < typename... Args > @@ -184,11 +192,19 @@ namespace meta_hpp } template < typename... Args > - std::optional constructor::safe_create_at(void* mem, Args&&... args) const { - if ( is_invocable_with(std::forward(args)...) ) { - return create_at(mem, std::forward(args)...); + uresult constructor::try_create_at(void* mem, Args&&... args) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const std::array vargs{uarg_base{registry, type_list{}}...}; + if ( const uerror err = state_->create_error(vargs) ) { + return err; + } } - return std::nullopt; + + const std::array vargs{uarg{registry, std::forward(args)}...}; + return state_->create_at(mem, vargs); } template < typename... Args > diff --git a/headers/meta.hpp/meta_states/destructor.hpp b/headers/meta.hpp/meta_states/destructor.hpp index fdfe725..54ea8ce 100644 --- a/headers/meta.hpp/meta_states/destructor.hpp +++ b/headers/meta.hpp/meta_states/destructor.hpp @@ -102,10 +102,32 @@ namespace meta_hpp return state_->destroy(varg); } + template < typename Arg > + uresult destructor::try_destroy(Arg&& arg) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const uarg_base varg{registry, std::forward(arg)}; + if ( const uerror err = state_->destroy_error(varg) ) { + return err; + } + } + + const uarg varg{registry, std::forward(arg)}; + state_->destroy(varg); + return uerror{error_code::no_error}; + } + inline void destructor::destroy_at(void* mem) const { state_->destroy_at(mem); } + inline uresult destructor::try_destroy_at(void* mem) const { + state_->destroy_at(mem); + return uerror{error_code::no_error}; + } + template < typename Arg > bool destructor::is_invocable_with() const noexcept { using namespace detail; diff --git a/headers/meta.hpp/meta_states/evalue.hpp b/headers/meta.hpp/meta_states/evalue.hpp index 3b6e391..ecdf40d 100644 --- a/headers/meta.hpp/meta_states/evalue.hpp +++ b/headers/meta.hpp/meta_states/evalue.hpp @@ -45,24 +45,4 @@ namespace meta_hpp inline const uvalue& evalue::get_underlying_value() const noexcept { return state_->underlying_value; } - - template < detail::enum_kind Enum > - Enum evalue::get_value_as() const { - return get_value().get_as(); - } - - template < detail::enum_kind Enum > - std::optional evalue::safe_get_value_as() const noexcept { - return get_value().safe_get_as(); - } - - template < detail::number_kind Number > - Number evalue::get_underlying_value_as() const { - return get_underlying_value().get_as(); - } - - template < detail::number_kind Number > - std::optional evalue::safe_get_underlying_value_as() const noexcept { - return get_underlying_value().safe_get_as(); - } } diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 1f1a297..1dcbc2c 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -148,11 +148,19 @@ namespace meta_hpp } template < typename... Args > - std::optional function::safe_invoke(Args&&... args) const { - if ( is_invocable_with(std::forward(args)...) ) { - return invoke(std::forward(args)...); + uresult function::try_invoke(Args&&... args) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const std::array vargs{uarg_base{registry, std::forward(args)}...}; + if ( const uerror err = state_->invoke_error(vargs) ) { + return err; + } } - return std::nullopt; + + const std::array vargs{uarg{registry, std::forward(args)}...}; + return state_->invoke(vargs); } template < typename... Args > diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index 4865936..5622bad 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -225,21 +225,24 @@ namespace meta_hpp } template < typename Instance > - std::optional member::safe_get(Instance&& instance) const { - if ( is_gettable_with(std::forward(instance)) ) { - return get(std::forward(instance)); + uresult member::try_get(Instance&& instance) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; + + { + const uinst_base vinst{registry, std::forward(instance)}; + if ( const uerror err = state_->getter_error(vinst) ) { + return err; + } } - return std::nullopt; + + const uinst vinst{registry, std::forward(instance)}; + return state_->getter(vinst); } - template < typename T, typename Instance > - T member::get_as(Instance&& instance) const { - return get(std::forward(instance)).template get_as(); - } - - template < typename T, typename Instance > - std::optional member::safe_get_as(Instance&& instance) const { - return safe_get(std::forward(instance)).value_or(uvalue{}).template safe_get_as(); + template < typename Instance > + uvalue member::operator()(Instance&& instance) const { + return get(std::forward(instance)); } template < typename Instance, typename Value > @@ -252,17 +255,22 @@ namespace meta_hpp } template < typename Instance, typename Value > - bool member::safe_set(Instance&& instance, Value&& value) const { - if ( is_settable_with(std::forward(instance), std::forward(value)) ) { - set(std::forward(instance), std::forward(value)); - return true; - } - return false; - } + uresult member::try_set(Instance&& instance, Value&& value) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; - template < typename Instance > - uvalue member::operator()(Instance&& instance) const { - return get(std::forward(instance)); + { + const uinst_base vinst{registry, std::forward(instance)}; + const uarg_base vvalue{registry, std::forward(value)}; + if ( const uerror err = state_->setter_error(vinst, vvalue) ) { + return err; + } + } + + const uinst vinst{registry, std::forward(instance)}; + const uarg vvalue{registry, std::forward(value)}; + state_->setter(vinst, vvalue); + return uerror{error_code::no_error}; } template < typename Instance, typename Value > diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index 8e22566..5ef2056 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -160,14 +160,6 @@ namespace meta_hpp return state_->invoke(vinst, vargs); } - template < typename Instance, typename... Args > - std::optional method::safe_invoke(Instance&& instance, Args&&... args) const { - if ( is_invocable_with(std::forward(instance), std::forward(args)...) ) { - return invoke(std::forward(instance), std::forward(args)...); - } - return std::nullopt; - } - template < typename Instance, typename... Args > uresult method::try_invoke(Instance&& instance, Args&&... args) const { using namespace detail; diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 93a789a..655f2fb 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -140,18 +140,12 @@ namespace meta_hpp return state_->getter(); } - inline std::optional variable::safe_get() const { + inline uresult variable::try_get() const { return state_->getter(); } - template < typename T > - T variable::get_as() const { - return get().template get_as(); - } - - template < typename T > - std::optional variable::safe_get_as() const { - return safe_get().value_or(uvalue{}).template safe_get_as(); + inline uvalue variable::operator()() const { + return get(); } template < typename Value > @@ -163,16 +157,20 @@ namespace meta_hpp } template < typename Value > - bool variable::safe_set(Value&& value) const { - if ( is_settable_with(std::forward(value)) ) { - set(std::forward(value)); - return true; - } - return false; - } + uresult variable::try_set(Value&& value) const { + using namespace detail; + type_registry& registry{type_registry::instance()}; - inline uvalue variable::operator()() const { - return get(); + { + const uarg_base vvalue{registry, std::forward(value)}; + if ( const uerror err = state_->setter_error(vvalue) ) { + return err; + } + } + + const uarg vvalue{registry, std::forward(value)}; + state_->setter(vvalue); + return uerror{error_code::no_error}; } template < typename Value > diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index dad913c..1c179e7 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -246,12 +246,6 @@ namespace meta_hpp template < detail::enum_kind Enum > [[nodiscard]] std::string_view value_to_name(Enum value) const noexcept; [[nodiscard]] uvalue name_to_value(std::string_view name) const noexcept; - - template < detail::enum_kind Enum > - [[nodiscard]] Enum name_to_value_as(std::string_view name) const; - - template < detail::enum_kind Enum > - [[nodiscard]] std::optional safe_name_to_value_as(std::string_view name) const noexcept; }; class function_type final : public type_base { diff --git a/headers/meta.hpp/meta_types/enum_type.hpp b/headers/meta.hpp/meta_types/enum_type.hpp index 232ee4d..56a3126 100644 --- a/headers/meta.hpp/meta_types/enum_type.hpp +++ b/headers/meta.hpp/meta_types/enum_type.hpp @@ -57,7 +57,7 @@ namespace meta_hpp } for ( const evalue& evalue : data_->evalues ) { - if ( evalue.get_value_as() == value ) { + if ( evalue.get_value().get_as() == value ) { return evalue.get_name(); } } @@ -72,14 +72,4 @@ namespace meta_hpp return uvalue{}; } - - template < detail::enum_kind Enum > - Enum enum_type::name_to_value_as(std::string_view name) const { - return name_to_value(name).get_as(); - } - - template < detail::enum_kind Enum > - std::optional enum_type::safe_name_to_value_as(std::string_view name) const noexcept { - return name_to_value(name).safe_get_as(); - } } diff --git a/headers/meta.hpp/meta_uvalue.hpp b/headers/meta.hpp/meta_uvalue.hpp index 51f1b62..28765ba 100644 --- a/headers/meta.hpp/meta_uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue.hpp @@ -103,15 +103,6 @@ namespace meta_hpp [[nodiscard]] auto try_get_as() const noexcept // -> std::conditional_t, T, const T*>; - template < typename T > - [[nodiscard]] std::optional safe_get_as() &&; - - template < typename T > - [[nodiscard]] std::optional safe_get_as() &; - - template < typename T > - [[nodiscard]] std::optional safe_get_as() const&; - private: struct vtable_t; diff --git a/headers/meta.hpp/meta_uvalue/uvalue.hpp b/headers/meta.hpp/meta_uvalue/uvalue.hpp index 0691c61..5d2441a 100644 --- a/headers/meta.hpp/meta_uvalue/uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue/uvalue.hpp @@ -635,55 +635,4 @@ namespace meta_hpp return nullptr; } - - template < typename T > - std::optional uvalue::safe_get_as() && { - static_assert(std::is_same_v>); - - if constexpr ( detail::pointer_kind ) { - if ( T ptr = try_get_as(); ptr || get_type().is_nullptr() ) { - return ptr; - } - } else { - if ( T* ptr = try_get_as() ) { - return std::move(*ptr); - } - } - - return std::nullopt; - } - - template < typename T > - std::optional uvalue::safe_get_as() & { - static_assert(std::is_same_v>); - - if constexpr ( detail::pointer_kind ) { - if ( T ptr = try_get_as(); ptr || get_type().is_nullptr() ) { - return ptr; - } - } else { - if ( T* ptr = try_get_as() ) { - return *ptr; - } - } - - return std::nullopt; - } - - template < typename T > - std::optional uvalue::safe_get_as() const& { - static_assert(std::is_same_v>); - - if constexpr ( detail::pointer_kind ) { - if ( T ptr = try_get_as(); ptr || get_type().is_nullptr() ) { - return ptr; - } - } else { - if ( const T* ptr = try_get_as() ) { - return *ptr; - } - } - - return std::nullopt; - } }