mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 03:29:28 +07:00
reduce some boilerplate
This commit is contained in:
@@ -24,7 +24,7 @@ namespace meta_hpp::detail
|
||||
};
|
||||
|
||||
public:
|
||||
uarg_base() = delete;
|
||||
uarg_base() = default;
|
||||
~uarg_base() = default;
|
||||
|
||||
uarg_base(uarg_base&&) = default;
|
||||
@@ -94,7 +94,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
class uarg final : public uarg_base {
|
||||
public:
|
||||
uarg() = delete;
|
||||
uarg() = default;
|
||||
~uarg() = default;
|
||||
|
||||
uarg(uarg&&) = default;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace meta_hpp::detail
|
||||
};
|
||||
|
||||
public:
|
||||
uinst_base() = delete;
|
||||
uinst_base() = default;
|
||||
~uinst_base() = default;
|
||||
|
||||
uinst_base(uinst_base&&) = default;
|
||||
@@ -99,7 +99,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
class uinst final : public uinst_base {
|
||||
public:
|
||||
uinst() = delete;
|
||||
uinst() = default;
|
||||
~uinst() = default;
|
||||
|
||||
uinst(uinst&&) = default;
|
||||
|
||||
@@ -27,12 +27,8 @@ namespace meta_hpp
|
||||
template < detail::function_pointer_kind Function, typename... Args >
|
||||
uvalue invoke(Function function_ptr, Args&&... args) {
|
||||
using namespace detail;
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return raw_function_invoke<function_policy::as_copy_t>(function_ptr, vargs);
|
||||
} else {
|
||||
return raw_function_invoke<function_policy::as_copy_t>(function_ptr, {});
|
||||
}
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return raw_function_invoke<function_policy::as_copy_t>(function_ptr, vargs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +58,8 @@ namespace meta_hpp
|
||||
uvalue invoke(Method method_ptr, Instance&& instance, Args&&... args) {
|
||||
using namespace detail;
|
||||
const uinst vinst{std::forward<Instance>(instance)};
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return raw_method_invoke<method_policy::as_copy_t>(method_ptr, vinst, vargs);
|
||||
} else {
|
||||
return raw_method_invoke<method_policy::as_copy_t>(method_ptr, vinst, {});
|
||||
}
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return raw_method_invoke<method_policy::as_copy_t>(method_ptr, vinst, vargs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,24 +77,16 @@ namespace meta_hpp
|
||||
|
||||
template < detail::function_pointer_kind Function, typename... Args >
|
||||
bool is_invocable_with() {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return raw_function_is_invocable_with<Function>(vargs);
|
||||
} else {
|
||||
return raw_function_is_invocable_with<Function>({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return raw_function_is_invocable_with<Function>(vargs);
|
||||
}
|
||||
|
||||
template < detail::function_pointer_kind Function, typename... Args >
|
||||
bool is_invocable_with(Args&&... args) {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return raw_function_is_invocable_with<Function>(vargs);
|
||||
} else {
|
||||
return raw_function_is_invocable_with<Function>({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return raw_function_is_invocable_with<Function>(vargs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,23 +133,15 @@ namespace meta_hpp
|
||||
bool is_invocable_with() {
|
||||
using namespace detail;
|
||||
const uinst_base vinst{type_list<Instance>{}};
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return raw_method_is_invocable_with<Method>(vinst, vargs);
|
||||
} else {
|
||||
return raw_method_is_invocable_with<Method>(vinst, {});
|
||||
}
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return raw_method_is_invocable_with<Method>(vinst, vargs);
|
||||
}
|
||||
|
||||
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
|
||||
bool is_invocable_with(Instance&& instance, Args&&... args) {
|
||||
using namespace detail;
|
||||
const uinst_base vinst{std::forward<Instance>(instance)};
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return raw_method_is_invocable_with<Method>(vinst, vargs);
|
||||
} else {
|
||||
return raw_method_is_invocable_with<Method>(vinst, {});
|
||||
}
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return raw_method_is_invocable_with<Method>(vinst, vargs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,13 +165,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename... Args >
|
||||
uvalue constructor::create(Args&&... args) const {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->create(vargs);
|
||||
} else {
|
||||
return state_->create({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->create(vargs);
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
@@ -184,13 +180,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename... Args >
|
||||
uvalue constructor::create_at(void* mem, Args&&... args) const {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->create_at(mem, vargs);
|
||||
} else {
|
||||
return state_->create_at(mem, {});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->create_at(mem, vargs);
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
@@ -203,24 +195,16 @@ namespace meta_hpp
|
||||
|
||||
template < typename... Args >
|
||||
bool constructor::is_invocable_with() const noexcept {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
} else {
|
||||
return state_->is_invocable_with({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
bool constructor::is_invocable_with(Args&&... args) const noexcept {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
} else {
|
||||
return state_->is_invocable_with({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
}
|
||||
|
||||
inline argument constructor::get_argument(std::size_t position) const noexcept {
|
||||
|
||||
@@ -144,13 +144,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename... Args >
|
||||
uvalue function::invoke(Args&&... args) const {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->invoke(vargs);
|
||||
} else {
|
||||
return state_->invoke({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->invoke(vargs);
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
@@ -168,24 +164,16 @@ namespace meta_hpp
|
||||
|
||||
template < typename... Args >
|
||||
bool function::is_invocable_with() const noexcept {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
} else {
|
||||
return state_->is_invocable_with({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
}
|
||||
|
||||
template < typename... Args >
|
||||
bool function::is_invocable_with(Args&&... args) const noexcept {
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
} else {
|
||||
return state_->is_invocable_with({});
|
||||
}
|
||||
using namespace detail;
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return state_->is_invocable_with(vargs);
|
||||
}
|
||||
|
||||
inline argument function::get_argument(std::size_t position) const noexcept {
|
||||
|
||||
@@ -160,12 +160,8 @@ namespace meta_hpp
|
||||
uvalue method::invoke(Instance&& instance, Args&&... args) const {
|
||||
using namespace detail;
|
||||
const uinst vinst{std::forward<Instance>(instance)};
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->invoke(vinst, vargs);
|
||||
} else {
|
||||
return state_->invoke(vinst, {});
|
||||
}
|
||||
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
|
||||
return state_->invoke(vinst, vargs);
|
||||
}
|
||||
|
||||
template < typename Instance, typename... Args >
|
||||
@@ -185,24 +181,16 @@ namespace meta_hpp
|
||||
bool method::is_invocable_with() const noexcept {
|
||||
using namespace detail;
|
||||
const uinst_base vinst{type_list<Instance>{}};
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return state_->is_invocable_with(vinst, vargs);
|
||||
} else {
|
||||
return state_->is_invocable_with(vinst, {});
|
||||
}
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
|
||||
return state_->is_invocable_with(vinst, vargs);
|
||||
}
|
||||
|
||||
template < typename Instance, typename... Args >
|
||||
bool method::is_invocable_with(Instance&& instance, Args&&... args) const noexcept {
|
||||
using namespace detail;
|
||||
const uinst_base vinst{std::forward<Instance>(instance)};
|
||||
if constexpr ( sizeof...(Args) > 0 ) {
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return state_->is_invocable_with(vinst, vargs);
|
||||
} else {
|
||||
return state_->is_invocable_with(vinst, {});
|
||||
}
|
||||
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
|
||||
return state_->is_invocable_with(vinst, vargs);
|
||||
}
|
||||
|
||||
inline argument method::get_argument(std::size_t position) const noexcept {
|
||||
|
||||
Reference in New Issue
Block a user