Permalink
Browse files

C++17: Replace some call_*() helpers with std::apply().

  • Loading branch information...
murraycu committed Apr 7, 2018
1 parent 025934b commit 7c88951dc959896feed019e19c7a457296c10c0c
Showing with 4 additions and 45 deletions.
  1. +2 −18 sigc++/adaptors/bind.h
  2. +1 −16 sigc++/adaptors/hide.h
  3. +1 −11 sigc++/signal.h
View
@@ -150,9 +150,7 @@ struct bind_functor : public adapts<T_functor>
const auto t_end = internal::tuple_end<t_args_size - I_location>(t_args);
const auto t_with_bound = std::tuple_cat(t_start, t_bound, t_end);
constexpr const auto seq =
std::make_index_sequence<std::tuple_size<decltype(t_with_bound)>::value>();
return call_functor_operator_parentheses(t_with_bound, seq);
return std::apply(this->functor_, t_with_bound);
}
/** Constructs a bind_functor object that binds an argument to the passed functor.
@@ -167,12 +165,6 @@ struct bind_functor : public adapts<T_functor>
private:
/// The arguments bound to the functor.
std::tuple<bound_argument<T_bound>...> bound_;
template <typename T, std::size_t... Is>
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
{
return (this->functor_)(std::get<Is>(std::forward<T>(tuple))...);
}
};
/** Adaptor that binds argument(s) to the wrapped functor.
@@ -199,8 +191,7 @@ struct bind_functor<-1, T_functor, T_type...> : public adapts<T_functor>
const auto t_bound = internal::tuple_transform_each<internal::TransformEachInvoker>(bound_);
const auto t_with_bound = std::tuple_cat(t_args, t_bound);
constexpr auto seq = std::make_index_sequence<std::tuple_size<decltype(t_with_bound)>::value>();
return call_functor_operator_parentheses(t_with_bound, seq);
return std::apply(this->functor_, t_with_bound);
}
/** Constructs a bind_functor object that binds an argument to the passed functor.
@@ -214,13 +205,6 @@ struct bind_functor<-1, T_functor, T_type...> : public adapts<T_functor>
/// The argument bound to the functor.
std::tuple<bound_argument<T_type>...> bound_;
private:
template <typename T, std::size_t... Is>
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
{
return (this->functor_)(std::get<Is>(std::forward<T>(tuple))...);
}
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
View
@@ -102,28 +102,13 @@ struct hide_functor : public adapts<T_functor>
const auto t_end = internal::tuple_end<size - index_ignore - 1>(t);
const auto t_used = std::tuple_cat(t_start, t_end);
constexpr auto size_used = size - 1;
// TODO: Remove these? They are just here as a sanity check.
static_assert(std::tuple_size<decltype(t_used)>::value == size_used, "Unexpected t_used size.");
const auto seq = std::make_index_sequence<size_used>();
return call_functor_operator_parentheses(t_used, seq);
return std::apply(this->functor_, t_used);
}
/** Constructs a hide_functor object that adds a dummy parameter to the passed functor.
* @param func Functor to invoke from operator()().
*/
explicit hide_functor(const T_functor& func) : adapts<T_functor>(func) {}
private:
// TODO_variadic: Replace this with std::experimental::apply() if that becomes standard
// C++, or add our own implementation, to avoid code duplication.
template <typename T_tuple, std::size_t... Is>
decltype(auto) call_functor_operator_parentheses(T_tuple& tuple, std::index_sequence<Is...>)
{
return this->functor_.template operator()(std::get<Is>(tuple)...);
}
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
View
@@ -246,8 +246,7 @@ struct signal_emit
*/
T_return operator()(const slot_type& slot) const
{
const auto seq = std::make_index_sequence<std::tuple_size<decltype(a_)>::value>();
return call_call_type_operator_parentheses_with_tuple(slot, a_, seq);
return std::apply(slot, a_);
}
/** Executes a list of slots using an accumulator of type @e T_accumulator.
@@ -274,15 +273,6 @@ struct signal_emit
private:
std::tuple<type_trait_take_t<T_arg>...> a_;
// TODO_variadic: Replace this with std::experimental::apply() if that becomes standard
// C++, or add our own implementation, to avoid code duplication.
template <std::size_t... Is>
decltype(auto) call_call_type_operator_parentheses_with_tuple(
const slot_type& slot, const std::tuple<T_arg...>& tuple, std::index_sequence<Is...>) const
{
return (slot)(std::get<Is>(tuple)...);
}
};
/** Abstracts signal emission.

0 comments on commit 7c88951

Please sign in to comment.