From 8eb15af7be3ced92425ea2bac613bd7491dac88c Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 26 Nov 2021 08:18:18 +0700 Subject: [PATCH] class_type create function --- headers/meta.hpp/meta_types.hpp | 6 ++++++ headers/meta.hpp/meta_types/class_type.hpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index 45546aa..d4ba9ac 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -201,6 +201,12 @@ namespace meta_hpp const method_map& get_methods() const noexcept; const variable_map& get_variables() const noexcept; + template < typename... Args > + std::optional create(Args&&... args) const; + + template < typename... Args > + std::optional operator()(Args&&... args) const; + template < detail::class_kind Derived > bool is_base_of() const noexcept; bool is_base_of(const class_type& derived) const noexcept; diff --git a/headers/meta.hpp/meta_types/class_type.hpp b/headers/meta.hpp/meta_types/class_type.hpp index 62118b8..5d88614 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -91,6 +91,21 @@ namespace meta_hpp return data_->variables; } + template < typename... Args > + std::optional class_type::create(Args&&... args) const { + for ( auto&& ctor : data_->ctors ) { + if ( ctor.second.is_invocable_with() ) { + return ctor.second.invoke(std::forward(args)...); + } + } + return std::nullopt; + } + + template < typename... Args > + std::optional class_type::operator()(Args&&... args) const { + return create(std::forward(args)...); + } + template < detail::class_kind Derived > bool class_type::is_base_of() const noexcept { return is_base_of(resolve_type());