mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
add class_type::get_destructor method
This commit is contained in:
@@ -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 >
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user