[libsigcplusplus/c++17v4: 3/3] C++17: Replace call_*() helpers with std::apply().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus/c++17v4: 3/3] C++17: Replace call_*() helpers with std::apply().
- Date: Wed, 21 Sep 2016 07:20:02 +0000 (UTC)
commit e497c86718bd2d158372ab59721e79032c84eb0d
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Sep 21 09:18:03 2016 +0200
C++17: Replace call_*() helpers with std::apply().
sigc++/adaptors/bind.h | 20 ++------------------
sigc++/adaptors/hide.h | 17 +----------------
sigc++/signal.h | 12 +-----------
3 files changed, 4 insertions(+), 45 deletions(-)
---
diff --git a/sigc++/adaptors/bind.h b/sigc++/adaptors/bind.h
index e93250b..0c281f0 100644
--- a/sigc++/adaptors/bind.h
+++ b/sigc++/adaptors/bind.h
@@ -151,9 +151,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.
@@ -168,12 +166,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 std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
- }
};
/** Adaptor that binds argument(s) to the wrapped functor.
@@ -200,8 +192,7 @@ public:
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.
@@ -215,13 +206,6 @@ public:
/// 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 std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
- }
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
diff --git a/sigc++/adaptors/hide.h b/sigc++/adaptors/hide.h
index a6acdf3..8d9d145 100644
--- a/sigc++/adaptors/hide.h
+++ b/sigc++/adaptors/hide.h
@@ -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 std::invoke(this->functor_, std::get<Is>(tuple)...);
- }
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
diff --git a/sigc++/signal.h b/sigc++/signal.h
index e6a6090..6b26cac 100644
--- a/sigc++/signal.h
+++ b/sigc++/signal.h
@@ -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 std::invoke(slot, std::get<Is>(tuple)...);
- }
};
/** Abstracts signal emission.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]