From 0e2d886d453877eb3ed26f233b601253053330fa Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 11 Jan 2023 13:40:18 +0700 Subject: [PATCH] move destructor auto bind to class_bind ctor --- develop/manuals/meta_manuals/inplace_manual.cpp | 2 +- develop/singles/headers/meta.hpp/meta_all.hpp | 12 +++++------- headers/meta.hpp/meta_binds.hpp | 8 +------- headers/meta.hpp/meta_binds/class_bind.hpp | 4 ++++ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/develop/manuals/meta_manuals/inplace_manual.cpp b/develop/manuals/meta_manuals/inplace_manual.cpp index 9144d64..506bc5f 100644 --- a/develop/manuals/meta_manuals/inplace_manual.cpp +++ b/develop/manuals/meta_manuals/inplace_manual.cpp @@ -62,5 +62,5 @@ TEST_CASE("meta/meta_examples/inplace") { CHECK(ivec2_length2(ivec2_ptr) == 13); // you must manually call the object's destructor - ivec2_type.destroy_at(ivec2_buffer.get_memory()); + CHECK(ivec2_type.destroy_at(ivec2_buffer.get_memory())); } diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 539501a..1e4df49 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -3655,13 +3655,7 @@ namespace meta_hpp template < detail::class_kind Class > class_bind class_(metadata_map metadata = {}) { - class_bind bind{std::move(metadata)}; - - if constexpr ( std::is_destructible_v ) { - bind.destructor_(); - } - - return bind; + return class_bind{std::move(metadata)}; } template < detail::enum_kind Enum > @@ -3812,6 +3806,10 @@ namespace meta_hpp : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); + + if constexpr ( std::is_destructible_v ) { + destructor_(); + } } template < detail::class_kind Class > diff --git a/headers/meta.hpp/meta_binds.hpp b/headers/meta.hpp/meta_binds.hpp index 7756e34..adcd7bb 100644 --- a/headers/meta.hpp/meta_binds.hpp +++ b/headers/meta.hpp/meta_binds.hpp @@ -419,13 +419,7 @@ namespace meta_hpp template < detail::class_kind Class > class_bind class_(metadata_map metadata = {}) { - class_bind bind{std::move(metadata)}; - - if constexpr ( std::is_destructible_v ) { - bind.destructor_(); - } - - return bind; + return class_bind{std::move(metadata)}; } template < detail::enum_kind Enum > diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index d711126..b86ee7c 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -17,6 +17,10 @@ namespace meta_hpp : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); + + if constexpr ( std::is_destructible_v ) { + destructor_(); + } } template < detail::class_kind Class >