mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
invoke syntactic sugar
This commit is contained in:
@@ -103,7 +103,7 @@ namespace meta_hpp
|
||||
template < typename... Args >
|
||||
std::optional<ctor_info> get_ctor() const {
|
||||
for ( auto&& family_info : ctors_ ) {
|
||||
if ( family_info.second.is_invocable_with<Args...>() ) {
|
||||
if ( family_info.second.is_invocable<Args...>() ) {
|
||||
return family_info.second;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +131,18 @@ namespace meta_hpp
|
||||
}
|
||||
}
|
||||
|
||||
template < typename R, typename... Args >
|
||||
R invoke_r(Args&&... args) const {
|
||||
return invoke(std::forward<Args>(args)...).template cast<R>();
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
bool is_invocable_with() const noexcept {
|
||||
value operator()(Args&&... args) const {
|
||||
return invoke(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
bool is_invocable() const noexcept {
|
||||
return ctor_detail::parameters_equal<Args...>(argument_types_);
|
||||
}
|
||||
|
||||
|
||||
@@ -122,9 +122,23 @@ namespace meta_hpp
|
||||
return getter_(instance);
|
||||
}
|
||||
|
||||
template < typename R >
|
||||
R get_r(cinstance instance) const {
|
||||
return get(instance).cast<R>();
|
||||
}
|
||||
|
||||
template < typename Value >
|
||||
void set(instance instance, Value&& value) const {
|
||||
return setter_(instance, std::forward<Value>(value));
|
||||
setter_(instance, std::forward<Value>(value));
|
||||
}
|
||||
|
||||
value operator()(cinstance instance) const {
|
||||
return get(instance);
|
||||
}
|
||||
|
||||
template < typename Value >
|
||||
void operator()(instance instance, Value&& value) const {
|
||||
set(instance, std::forward<Value>(value));
|
||||
}
|
||||
|
||||
template < typename F >
|
||||
|
||||
@@ -134,6 +134,19 @@ namespace meta_hpp
|
||||
}
|
||||
}
|
||||
|
||||
template < typename R, typename... Args >
|
||||
std::optional<R> invoke_r(Args&&... args) const {
|
||||
if ( std::optional<value> r = invoke(std::forward<Args>(args)...) ) {
|
||||
return std::move(r)->template cast<R>();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
std::optional<value> operator()(Args&&... args) const {
|
||||
return invoke(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const {
|
||||
for ( auto&& id_info : datas_ ) {
|
||||
|
||||
@@ -208,20 +208,31 @@ namespace meta_hpp
|
||||
std::optional<value> invoke(T& inst, Args&&... args) const {
|
||||
if constexpr ( sizeof...(Args) > 0u ) {
|
||||
std::array<value, sizeof...(Args)> vargs{std::forward<Args>(args)...};
|
||||
return invoke_(inst, vargs.data(), vargs.size());
|
||||
if constexpr ( std::is_const_v<T> ) {
|
||||
return cinvoke_(inst, vargs.data(), vargs.size());
|
||||
} else {
|
||||
return invoke_(inst, vargs.data(), vargs.size());
|
||||
}
|
||||
} else {
|
||||
return invoke_(inst, nullptr, 0u);
|
||||
if constexpr ( std::is_const_v<T> ) {
|
||||
return cinvoke_(inst, nullptr, 0u);
|
||||
} else {
|
||||
return invoke_(inst, nullptr, 0u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T, typename... Args >
|
||||
std::optional<value> invoke(const T& inst, Args&&... args) const {
|
||||
if constexpr ( sizeof...(Args) > 0u ) {
|
||||
std::array<value, sizeof...(Args)> vargs{std::forward<Args>(args)...};
|
||||
return cinvoke_(inst, vargs.data(), vargs.size());
|
||||
} else {
|
||||
return cinvoke_(inst, nullptr, 0u);
|
||||
template < typename R, typename T, typename... Args >
|
||||
std::optional<R> invoke_r(T& inst, Args&&... args) const {
|
||||
if ( std::optional<value> r = invoke(inst, std::forward<Args>(args)...) ) {
|
||||
return std::move(r)->template cast<R>();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template < typename T, typename... Args >
|
||||
std::optional<value> operator()(T& inst, Args&&... args) const {
|
||||
return invoke(inst, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template < typename F >
|
||||
|
||||
@@ -96,11 +96,25 @@ namespace meta_hpp
|
||||
return getter_();
|
||||
}
|
||||
|
||||
template < typename R >
|
||||
R get_r() const {
|
||||
return get().cast<R>();
|
||||
}
|
||||
|
||||
template < typename Value >
|
||||
void set(Value&& value) const {
|
||||
return setter_(std::forward<Value>(value));
|
||||
}
|
||||
|
||||
value operator()() const {
|
||||
return get();
|
||||
}
|
||||
|
||||
template < typename Value >
|
||||
void operator()(Value&& value) const {
|
||||
return set(std::forward<Value>(value));
|
||||
}
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const {
|
||||
for ( auto&& id_info : datas_ ) {
|
||||
|
||||
Reference in New Issue
Block a user