add class_type::get_destructor method

This commit is contained in:
BlackMATov
2023-01-01 12:48:09 +07:00
parent 1c44fece15
commit 3ed405b1ed
4 changed files with 36 additions and 6 deletions

View File

@@ -195,6 +195,8 @@ namespace meta_hpp
[[nodiscard]] constructor get_constructor_with(std::span<const any_type> args) const noexcept;
[[nodiscard]] constructor get_constructor_with(std::initializer_list<any_type> 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 >

View File

@@ -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
//

View File

@@ -1588,6 +1588,8 @@ namespace meta_hpp
[[nodiscard]] constructor get_constructor_with(std::span<const any_type> args) const noexcept;
[[nodiscard]] constructor get_constructor_with(std::initializer_list<any_type> 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
//

View File

@@ -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<clazz_opened_dtor>());
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<clazz_virtual_dtor>());
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<clazz_virtual_dtor>());
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<clazz_dtor_metadata>());
CHECK(dtor.get_type().get_flags() == (meta::destructor_flags::is_noexcept | meta::destructor_flags::is_virtual));