style fixes

This commit is contained in:
BlackMATov
2021-11-29 23:39:45 +07:00
parent a901d6f386
commit f199ec508f
4 changed files with 46 additions and 35 deletions

View File

@@ -57,17 +57,17 @@ namespace meta_hpp::detail
{
template < class_kind Class, typename... Args, std::size_t... Is >
bool raw_ctor_is_invocable_with_impl(
const arg_base* arg_bases,
const arg_base* args,
std::index_sequence<Is...>)
{
using ct = ctor_traits<Class, Args...>;
using argument_types = typename ct::argument_types;
return (... && (arg_bases + Is)->can_cast_to<type_list_at_t<Is, argument_types>>() );
return (... && (args + Is)->can_cast_to<type_list_at_t<Is, argument_types>>() );
}
template < class_kind Class, typename... Args >
bool raw_ctor_is_invocable_with(
const arg_base* arg_bases,
const arg_base* args,
std::size_t arg_count)
{
using ct = ctor_traits<Class, Args...>;
@@ -77,7 +77,7 @@ namespace meta_hpp::detail
}
return raw_ctor_is_invocable_with_impl<Class, Args...>(
arg_bases,
args,
std::make_index_sequence<ct::arity>());
}
@@ -126,8 +126,9 @@ namespace meta_hpp
template < typename... Args >
value ctor::invoke(Args&&... args) const {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg, sizeof...(Args)> vargs{detail::arg{std::forward<Args>(args)}...};
std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
return state_->invoke(vargs.data(), vargs.size());
} else {
return state_->invoke(nullptr, 0);
@@ -141,9 +142,10 @@ namespace meta_hpp
template < typename... Args >
bool ctor::is_invocable_with() const noexcept {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg_base, sizeof...(Args)> arg_bases{detail::arg_base{detail::type_list<Args>{}}...};
return state_->is_invocable_with(arg_bases.data(), arg_bases.size());
std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
return state_->is_invocable_with(vargs.data(), vargs.size());
} else {
return state_->is_invocable_with(nullptr, 0);
}
@@ -151,8 +153,9 @@ namespace meta_hpp
template < typename... Args >
bool ctor::is_invocable_with(Args&&... args) const noexcept {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg, sizeof...(Args)> vargs{detail::arg{std::forward<Args>(args)}...};
std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
return state_->is_invocable_with(vargs.data(), vargs.size());
} else {
return state_->is_invocable_with(nullptr, 0);

View File

@@ -67,17 +67,17 @@ namespace meta_hpp::detail
{
template < function_kind Function, std::size_t... Is >
bool raw_function_is_invocable_with_impl(
const arg_base* arg_bases,
const arg_base* args,
std::index_sequence<Is...>)
{
using ft = function_traits<Function>;
using argument_types = typename ft::argument_types;
return (... && (arg_bases + Is)->can_cast_to<type_list_at_t<Is, argument_types>>() );
return (... && (args + Is)->can_cast_to<type_list_at_t<Is, argument_types>>() );
}
template < function_kind Function >
bool raw_function_is_invocable_with(
const arg_base* arg_bases,
const arg_base* args,
std::size_t arg_count)
{
using ft = function_traits<Function>;
@@ -87,7 +87,7 @@ namespace meta_hpp::detail
}
return raw_function_is_invocable_with_impl<Function>(
arg_bases,
args,
std::make_index_sequence<ft::arity>());
}
@@ -140,8 +140,9 @@ namespace meta_hpp
template < typename... Args >
std::optional<value> function::invoke(Args&&... args) const {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg, sizeof...(Args)> vargs{detail::arg{std::forward<Args>(args)}...};
std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
return state_->invoke(vargs.data(), vargs.size());
} else {
return state_->invoke(nullptr, 0);
@@ -155,9 +156,10 @@ namespace meta_hpp
template < typename... Args >
bool function::is_invocable_with() const noexcept {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg_base, sizeof...(Args)> arg_bases{detail::arg_base{detail::type_list<Args>{}}...};
return state_->is_invocable_with(arg_bases.data(), arg_bases.size());
std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
return state_->is_invocable_with(vargs.data(), vargs.size());
} else {
return state_->is_invocable_with(nullptr, 0);
}
@@ -165,8 +167,9 @@ namespace meta_hpp
template < typename... Args >
bool function::is_invocable_with(Args&&... args) const noexcept {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg, sizeof...(Args)> vargs{detail::arg{std::forward<Args>(args)}...};
std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
return state_->is_invocable_with(vargs.data(), vargs.size());
} else {
return state_->is_invocable_with(nullptr, 0);

View File

@@ -114,11 +114,13 @@ namespace meta_hpp
template < typename Instance >
value member::get(Instance&& instance) const {
return state_->getter(detail::inst{std::forward<Instance>(instance)});
using namespace detail;
return state_->getter(inst{std::forward<Instance>(instance)});
}
template < typename Instance, typename Value >
void member::set(Instance&& instance, Value&& value) const {
state_->setter(detail::inst{std::forward<Instance>(instance)}, detail::arg{std::forward<Value>(value)});
using namespace detail;
state_->setter(inst{std::forward<Instance>(instance)}, arg{std::forward<Value>(value)});
}
}

View File

@@ -77,22 +77,22 @@ namespace meta_hpp::detail
{
template < method_kind Method, std::size_t... Is >
bool raw_method_is_invocable_with_impl(
const inst_base& inst_base,
const arg_base* arg_bases,
const inst_base& inst,
const arg_base* args,
std::index_sequence<Is...>)
{
using mt = method_traits<Method>;
using qualified_type = typename mt::qualified_type;
using argument_types = typename mt::argument_types;
return inst_base.can_cast_to<qualified_type>()
&& (... && (arg_bases + Is)->can_cast_to<type_list_at_t<Is, argument_types>>() );
return inst.can_cast_to<qualified_type>()
&& (... && (args + Is)->can_cast_to<type_list_at_t<Is, argument_types>>() );
}
template < method_kind Method >
bool raw_method_is_invocable_with(
const inst_base& inst_base,
const arg_base* arg_bases,
const inst_base& inst,
const arg_base* args,
std::size_t arg_count)
{
using mt = method_traits<Method>;
@@ -102,8 +102,8 @@ namespace meta_hpp::detail
}
return raw_method_is_invocable_with_impl<Method>(
inst_base,
arg_bases,
inst,
args,
std::make_index_sequence<mt::arity>());
}
@@ -156,11 +156,12 @@ namespace meta_hpp
template < typename Instance, typename... Args >
std::optional<value> method::invoke(Instance&& instance, Args&&... args) const {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg, sizeof...(Args)> vargs{detail::arg{std::forward<Args>(args)}...};
return state_->invoke(detail::inst{std::forward<Instance>(instance)}, vargs.data(), vargs.size());
std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
return state_->invoke(inst{std::forward<Instance>(instance)}, vargs.data(), vargs.size());
} else {
return state_->invoke(detail::inst{std::forward<Instance>(instance)}, nullptr, 0);
return state_->invoke(inst{std::forward<Instance>(instance)}, nullptr, 0);
}
}
@@ -171,21 +172,23 @@ namespace meta_hpp
template < typename Instance, typename... Args >
bool method::is_invocable_with() const noexcept {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg_base, sizeof...(Args)> arg_bases{detail::arg_base{detail::type_list<Args>{}}...};
return state_->is_invocable_with(detail::inst_base{detail::type_list<Instance>{}}, arg_bases.data(), arg_bases.size());
std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
return state_->is_invocable_with(inst_base{type_list<Instance>{}}, vargs.data(), vargs.size());
} else {
return state_->is_invocable_with(detail::inst_base{detail::type_list<Instance>{}}, nullptr, 0);
return state_->is_invocable_with(inst_base{type_list<Instance>{}}, nullptr, 0);
}
}
template < typename Instance, typename... Args >
bool method::is_invocable_with(Instance&& instance, Args&&... args) const noexcept {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
std::array<detail::arg, sizeof...(Args)> vargs{detail::arg{std::forward<Args>(args)}...};
return state_->is_invocable_with(detail::inst{std::forward<Instance>(instance)}, vargs.data(), vargs.size());
std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
return state_->is_invocable_with(inst{std::forward<Instance>(instance)}, vargs.data(), vargs.size());
} else {
return state_->is_invocable_with(detail::inst{std::forward<Instance>(instance)}, nullptr, 0);
return state_->is_invocable_with(inst{std::forward<Instance>(instance)}, nullptr, 0);
}
}
}