mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
class_type create function
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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>());
|
||||
|
||||
Reference in New Issue
Block a user