From 3ed405b1edcdcc88ceef81f0d587bd04b8920f9a Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 1 Jan 2023 12:48:09 +0700 Subject: [PATCH] add class_type::get_destructor method --- headers/meta.hpp/meta_types.hpp | 2 ++ headers/meta.hpp/meta_types/class_type.hpp | 15 ++++++++++++++- singles/headers/meta.hpp/meta_all.hpp | 17 ++++++++++++++++- untests/meta_states/dtor_tests.cpp | 8 ++++---- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index 4186992..c824293 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -195,6 +195,8 @@ namespace meta_hpp [[nodiscard]] constructor get_constructor_with(std::span args) const noexcept; [[nodiscard]] constructor get_constructor_with(std::initializer_list args) const noexcept; + [[nodiscard]] destructor get_destructor() const noexcept; + template < typename... Args > [[nodiscard]] function get_function_with(std::string_view name) const noexcept; template < typename Iter > diff --git a/headers/meta.hpp/meta_types/class_type.hpp b/headers/meta.hpp/meta_types/class_type.hpp index 62e3f35..81b0eca 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -274,7 +274,7 @@ namespace meta_hpp template < typename Iter > constructor class_type::get_constructor_with(Iter first, Iter last) const noexcept { - for ( auto&& [index, ctor] : data_->constructors ) { + for ( auto&& [_, 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; @@ -291,6 +291,19 @@ namespace meta_hpp return get_constructor_with(args.begin(), args.end()); } + // + // get_destructor + // + + inline destructor class_type::get_destructor() const noexcept { + if ( data_->destructors.empty() ) { + return destructor{}; + } + + auto&& [_, dtor] = *data_->destructors.begin(); + return dtor; + } + // // get_function_with // diff --git a/singles/headers/meta.hpp/meta_all.hpp b/singles/headers/meta.hpp/meta_all.hpp index ffce602..35a5381 100644 --- a/singles/headers/meta.hpp/meta_all.hpp +++ b/singles/headers/meta.hpp/meta_all.hpp @@ -1588,6 +1588,8 @@ namespace meta_hpp [[nodiscard]] constructor get_constructor_with(std::span args) const noexcept; [[nodiscard]] constructor get_constructor_with(std::initializer_list args) const noexcept; + [[nodiscard]] destructor get_destructor() const noexcept; + template < typename... Args > [[nodiscard]] function get_function_with(std::string_view name) const noexcept; template < typename Iter > @@ -7120,7 +7122,7 @@ namespace meta_hpp template < typename Iter > constructor class_type::get_constructor_with(Iter first, Iter last) const noexcept { - for ( auto&& [index, ctor] : data_->constructors ) { + for ( auto&& [_, 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; @@ -7137,6 +7139,19 @@ namespace meta_hpp return get_constructor_with(args.begin(), args.end()); } + // + // get_destructor + // + + inline destructor class_type::get_destructor() const noexcept { + if ( data_->destructors.empty() ) { + return destructor{}; + } + + auto&& [_, dtor] = *data_->destructors.begin(); + return dtor; + } + // // get_function_with // diff --git a/untests/meta_states/dtor_tests.cpp b/untests/meta_states/dtor_tests.cpp index e91730f..815781d 100644 --- a/untests/meta_states/dtor_tests.cpp +++ b/untests/meta_states/dtor_tests.cpp @@ -56,7 +56,7 @@ TEST_CASE("meta/meta_states/dtor") { REQUIRE(clazz_type); REQUIRE(clazz_type.get_destructors().size() == 1); - auto&& [_, dtor] = *clazz_type.get_destructors().begin(); + const meta::destructor dtor = clazz_type.get_destructor(); CHECK(dtor.get_type().get_class_type() == meta::resolve_type()); CHECK(dtor.get_type().get_flags() == meta::destructor_flags::is_noexcept); @@ -67,7 +67,7 @@ TEST_CASE("meta/meta_states/dtor") { REQUIRE(clazz_type); REQUIRE(clazz_type.get_destructors().size() == 1); - auto&& [_, dtor] = *clazz_type.get_destructors().begin(); + const meta::destructor dtor = clazz_type.get_destructor(); CHECK(dtor.get_type().get_class_type() == meta::resolve_type()); CHECK(dtor.get_type().get_flags() == meta::destructor_flags::is_virtual); @@ -78,7 +78,7 @@ TEST_CASE("meta/meta_states/dtor") { REQUIRE(clazz_type); REQUIRE(clazz_type.get_destructors().size() == 1); - auto&& [_, dtor] = *clazz_type.get_destructors().begin(); + const meta::destructor dtor = clazz_type.get_destructor(); CHECK(dtor.get_type().get_class_type() == meta::resolve_type()); CHECK(dtor.get_type().get_flags() == meta::destructor_flags::is_virtual); @@ -89,7 +89,7 @@ TEST_CASE("meta/meta_states/dtor") { REQUIRE(clazz_type); REQUIRE(clazz_type.get_destructors().size() == 1); - auto&& [_, dtor] = *clazz_type.get_destructors().begin(); + const meta::destructor dtor = clazz_type.get_destructor(); CHECK(dtor.get_type().get_class_type() == meta::resolve_type()); CHECK(dtor.get_type().get_flags() == (meta::destructor_flags::is_noexcept | meta::destructor_flags::is_virtual));