diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 94f3a43..43883bf 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -3613,6 +3613,7 @@ namespace meta_hpp [[nodiscard]] constructor_type get_type() const noexcept; + [[nodiscard]] std::size_t get_arity() const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; @@ -3710,6 +3711,7 @@ namespace meta_hpp [[nodiscard]] function_type get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; + [[nodiscard]] std::size_t get_arity() const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; @@ -3808,6 +3810,7 @@ namespace meta_hpp [[nodiscard]] method_type get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; + [[nodiscard]] std::size_t get_arity() const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; @@ -6353,6 +6356,10 @@ namespace meta_hpp return state_->index.get_name(); } + inline std::size_t function::get_arity() const noexcept { + return state_->arguments.size(); + } + inline argument function::get_argument(std::size_t position) const noexcept { return position < state_->arguments.size() ? state_->arguments[position] : argument{}; } @@ -7248,6 +7255,10 @@ namespace meta_hpp return state_->index.get_name(); } + inline std::size_t method::get_arity() const noexcept { + return state_->arguments.size(); + } + inline argument method::get_argument(std::size_t position) const noexcept { return position < state_->arguments.size() ? state_->arguments[position] : argument{}; } @@ -7868,6 +7879,10 @@ namespace meta_hpp return state_->index.get_type(); } + inline std::size_t constructor::get_arity() const noexcept { + return state_->arguments.size(); + } + inline argument constructor::get_argument(std::size_t position) const noexcept { return position < state_->arguments.size() ? state_->arguments[position] : argument{}; } @@ -8678,11 +8693,11 @@ namespace meta_hpp template < typename... Args > uvalue class_type::create(Args&&... args) const { - for ( const constructor& ctor : data_->constructors ) { - if ( ctor.is_invocable_with(META_HPP_FWD(args)...) ) { + for ( const constructor& constructor : data_->constructors ) { + if ( constructor.is_invocable_with(META_HPP_FWD(args)...) ) { // there is no 'use after move' here because // 'is_invocable_with' doesn't actually move 'args' - return ctor.create(META_HPP_FWD(args)...); + return constructor.create(META_HPP_FWD(args)...); } } return uvalue{}; @@ -8690,11 +8705,11 @@ namespace meta_hpp template < typename... Args > uvalue class_type::create_at(void* mem, Args&&... args) const { - for ( const constructor& ctor : data_->constructors ) { - if ( ctor.is_invocable_with(META_HPP_FWD(args)...) ) { + for ( const constructor& constructor : data_->constructors ) { + if ( constructor.is_invocable_with(META_HPP_FWD(args)...) ) { // there is no 'use after move' here because // 'is_invocable_with' doesn't actually move 'args' - return ctor.create_at(mem, META_HPP_FWD(args)...); + return constructor.create_at(mem, META_HPP_FWD(args)...); } } return uvalue{}; @@ -8702,11 +8717,11 @@ namespace meta_hpp template < typename Arg > bool class_type::destroy(Arg&& arg) const { - if ( const destructor& dtor = get_destructor() ) { - if ( dtor.is_invocable_with(META_HPP_FWD(arg)) ) { + if ( const destructor& destructor = get_destructor() ) { + if ( destructor.is_invocable_with(META_HPP_FWD(arg)) ) { // there is no 'use after move' here because // 'is_invocable_with' doesn't actually move an 'arg' - dtor.destroy(META_HPP_FWD(arg)); + destructor.destroy(META_HPP_FWD(arg)); return true; } } @@ -8714,8 +8729,8 @@ namespace meta_hpp } inline bool class_type::destroy_at(void* mem) const { - if ( const destructor& dtor = get_destructor() ) { - dtor.destroy_at(mem); + if ( const destructor& destructor = get_destructor() ) { + destructor.destroy_at(mem); return true; } return false; @@ -8877,10 +8892,12 @@ namespace meta_hpp template < typename Iter > constructor class_type::get_constructor_with(Iter first, Iter last) const noexcept { - for ( const constructor& ctor : data_->constructors ) { - const any_type_list& args = ctor.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { - return ctor; + for ( const constructor& constructor : data_->constructors ) { + const constructor_type& constructor_type = constructor.get_type(); + const any_type_list& constructor_args = constructor_type.get_argument_types(); + + if ( std::equal(first, last, constructor_args.begin(), constructor_args.end()) ) { + return constructor; } } return constructor{}; @@ -8930,8 +8947,10 @@ namespace meta_hpp continue; } - const any_type_list& args = function.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { + const function_type& function_type = function.get_type(); + const any_type_list& function_args = function_type.get_argument_types(); + + if ( std::equal(first, last, function_args.begin(), function_args.end()) ) { return function; } } @@ -8988,8 +9007,10 @@ namespace meta_hpp continue; } - const any_type_list& args = method.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { + const method_type& method_type = method.get_type(); + const any_type_list& method_args = method_type.get_argument_types(); + + if ( std::equal(first, last, method_args.begin(), method_args.end()) ) { return method; } } @@ -9099,8 +9120,10 @@ namespace meta_hpp continue; } - const any_type_list& args = function.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { + const function_type& function_type = function.get_type(); + const any_type_list& function_args = function_type.get_argument_types(); + + if ( std::equal(first, last, function_args.begin(), function_args.end()) ) { return function; } } diff --git a/develop/untests/meta_states/function2_tests.cpp b/develop/untests/meta_states/function2_tests.cpp index 401bee3..69a06c3 100644 --- a/develop/untests/meta_states/function2_tests.cpp +++ b/develop/untests/meta_states/function2_tests.cpp @@ -37,6 +37,7 @@ TEST_CASE("meta/meta_states/function2") { const meta::function func = ivec2_type.get_function("iadd"); REQUIRE(func); + CHECK(func.get_arity() == 2); CHECK(func.get_arguments().size() == 2); REQUIRE(func.get_argument(0)); @@ -56,6 +57,7 @@ TEST_CASE("meta/meta_states/function2") { const meta::function func = ivec2_type.get_function("isub"); REQUIRE(func); + CHECK(func.get_arity() == 2); REQUIRE(func.get_arguments().size() == 2); REQUIRE(func.get_argument(0)); diff --git a/develop/untests/meta_states/metadata_tests.cpp b/develop/untests/meta_states/metadata_tests.cpp index 6dff81e..d4fac8e 100644 --- a/develop/untests/meta_states/metadata_tests.cpp +++ b/develop/untests/meta_states/metadata_tests.cpp @@ -135,6 +135,8 @@ TEST_CASE("meta/meta_states/metadata/class") { const meta::constructor ivec2_ctor = ivec2_type.get_constructor_with(); REQUIRE(ivec2_ctor); + CHECK(ivec2_ctor.get_arity() == 1); + REQUIRE(ivec2_ctor.get_metadata().contains("desc")); CHECK(ivec2_ctor.get_metadata().at("desc").as() == "one arg 2d vector ctor"s); @@ -152,6 +154,8 @@ TEST_CASE("meta/meta_states/metadata/class") { const meta::constructor ivec2_ctor = ivec2_type.get_constructor_with(); REQUIRE(ivec2_ctor); + CHECK(ivec2_ctor.get_arity() == 2); + REQUIRE(ivec2_ctor.get_metadata().contains("desc")); CHECK(ivec2_ctor.get_metadata().at("desc").as() == "two args 2d vector ctor"s); @@ -204,6 +208,8 @@ TEST_CASE("meta/meta_states/metadata/class") { const meta::function ivec2_iadd = ivec2_type.get_function("iadd"); REQUIRE(ivec2_iadd); + CHECK(ivec2_iadd.get_arity() == 2); + REQUIRE(ivec2_iadd.get_metadata().contains("desc")); CHECK(ivec2_iadd.get_metadata().at("desc").as() == "iadd-function"s); diff --git a/develop/untests/meta_states/method2_tests.cpp b/develop/untests/meta_states/method2_tests.cpp index 1cd9145..1f51bce 100644 --- a/develop/untests/meta_states/method2_tests.cpp +++ b/develop/untests/meta_states/method2_tests.cpp @@ -34,6 +34,7 @@ TEST_CASE("meta/meta_states/method2") { const meta::method add_m = ivec2_type.get_method("add"); REQUIRE(add_m); + CHECK(add_m.get_arity() == 1); CHECK(add_m.get_arguments().size() == 1); REQUIRE(add_m.get_argument(0)); diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index 300bd12..2adac57 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -204,6 +204,7 @@ namespace meta_hpp [[nodiscard]] constructor_type get_type() const noexcept; + [[nodiscard]] std::size_t get_arity() const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; @@ -301,6 +302,7 @@ namespace meta_hpp [[nodiscard]] function_type get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; + [[nodiscard]] std::size_t get_arity() const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; @@ -399,6 +401,7 @@ namespace meta_hpp [[nodiscard]] method_type get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; + [[nodiscard]] std::size_t get_arity() const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 452d1fb..ee344df 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -170,6 +170,10 @@ namespace meta_hpp return state_->index.get_type(); } + inline std::size_t constructor::get_arity() const noexcept { + return state_->arguments.size(); + } + inline argument constructor::get_argument(std::size_t position) const noexcept { return position < state_->arguments.size() ? state_->arguments[position] : argument{}; } diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index ab8ca55..49dc105 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -144,6 +144,10 @@ namespace meta_hpp return state_->index.get_name(); } + inline std::size_t function::get_arity() const noexcept { + return state_->arguments.size(); + } + inline argument function::get_argument(std::size_t position) const noexcept { return position < state_->arguments.size() ? state_->arguments[position] : argument{}; } diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index a2027c2..df8e1b2 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -156,6 +156,10 @@ namespace meta_hpp return state_->index.get_name(); } + inline std::size_t method::get_arity() const noexcept { + return state_->arguments.size(); + } + inline argument method::get_argument(std::size_t position) const noexcept { return position < state_->arguments.size() ? state_->arguments[position] : argument{}; } diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index fd57ad1..8583961 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -93,8 +93,10 @@ namespace meta_hpp continue; } - const any_type_list& args = function.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { + const function_type& function_type = function.get_type(); + const any_type_list& function_args = function_type.get_argument_types(); + + if ( std::equal(first, last, function_args.begin(), function_args.end()) ) { return function; } } diff --git a/headers/meta.hpp/meta_types/class_type.hpp b/headers/meta.hpp/meta_types/class_type.hpp index 46d324f..5b69ddb 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -202,11 +202,11 @@ namespace meta_hpp template < typename... Args > uvalue class_type::create(Args&&... args) const { - for ( const constructor& ctor : data_->constructors ) { - if ( ctor.is_invocable_with(META_HPP_FWD(args)...) ) { + for ( const constructor& constructor : data_->constructors ) { + if ( constructor.is_invocable_with(META_HPP_FWD(args)...) ) { // there is no 'use after move' here because // 'is_invocable_with' doesn't actually move 'args' - return ctor.create(META_HPP_FWD(args)...); + return constructor.create(META_HPP_FWD(args)...); } } return uvalue{}; @@ -214,11 +214,11 @@ namespace meta_hpp template < typename... Args > uvalue class_type::create_at(void* mem, Args&&... args) const { - for ( const constructor& ctor : data_->constructors ) { - if ( ctor.is_invocable_with(META_HPP_FWD(args)...) ) { + for ( const constructor& constructor : data_->constructors ) { + if ( constructor.is_invocable_with(META_HPP_FWD(args)...) ) { // there is no 'use after move' here because // 'is_invocable_with' doesn't actually move 'args' - return ctor.create_at(mem, META_HPP_FWD(args)...); + return constructor.create_at(mem, META_HPP_FWD(args)...); } } return uvalue{}; @@ -226,11 +226,11 @@ namespace meta_hpp template < typename Arg > bool class_type::destroy(Arg&& arg) const { - if ( const destructor& dtor = get_destructor() ) { - if ( dtor.is_invocable_with(META_HPP_FWD(arg)) ) { + if ( const destructor& destructor = get_destructor() ) { + if ( destructor.is_invocable_with(META_HPP_FWD(arg)) ) { // there is no 'use after move' here because // 'is_invocable_with' doesn't actually move an 'arg' - dtor.destroy(META_HPP_FWD(arg)); + destructor.destroy(META_HPP_FWD(arg)); return true; } } @@ -238,8 +238,8 @@ namespace meta_hpp } inline bool class_type::destroy_at(void* mem) const { - if ( const destructor& dtor = get_destructor() ) { - dtor.destroy_at(mem); + if ( const destructor& destructor = get_destructor() ) { + destructor.destroy_at(mem); return true; } return false; @@ -401,10 +401,12 @@ namespace meta_hpp template < typename Iter > constructor class_type::get_constructor_with(Iter first, Iter last) const noexcept { - for ( const constructor& ctor : data_->constructors ) { - const any_type_list& args = ctor.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { - return ctor; + for ( const constructor& constructor : data_->constructors ) { + const constructor_type& constructor_type = constructor.get_type(); + const any_type_list& constructor_args = constructor_type.get_argument_types(); + + if ( std::equal(first, last, constructor_args.begin(), constructor_args.end()) ) { + return constructor; } } return constructor{}; @@ -454,8 +456,10 @@ namespace meta_hpp continue; } - const any_type_list& args = function.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { + const function_type& function_type = function.get_type(); + const any_type_list& function_args = function_type.get_argument_types(); + + if ( std::equal(first, last, function_args.begin(), function_args.end()) ) { return function; } } @@ -512,8 +516,10 @@ namespace meta_hpp continue; } - const any_type_list& args = method.get_type().get_argument_types(); - if ( std::equal(first, last, args.begin(), args.end()) ) { + const method_type& method_type = method.get_type(); + const any_type_list& method_args = method_type.get_argument_types(); + + if ( std::equal(first, last, method_args.begin(), method_args.end()) ) { return method; } }