class_type create function

This commit is contained in:
BlackMATov
2021-11-26 08:18:18 +07:00
parent 06ee563133
commit 8eb15af7be
2 changed files with 21 additions and 0 deletions

View File

@@ -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<value> create(Args&&... args) const;
template < typename... Args >
std::optional<value> 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;

View File

@@ -91,6 +91,21 @@ namespace meta_hpp
return data_->variables;
}
template < typename... Args >
std::optional<value> class_type::create(Args&&... args) const {
for ( auto&& ctor : data_->ctors ) {
if ( ctor.second.is_invocable_with<Args...>() ) {
return ctor.second.invoke(std::forward<Args>(args)...);
}
}
return std::nullopt;
}
template < typename... Args >
std::optional<value> class_type::operator()(Args&&... args) const {
return create(std::forward<Args>(args)...);
}
template < detail::class_kind Derived >
bool class_type::is_base_of() const noexcept {
return is_base_of(resolve_type<Derived>());