Skip to content

Commit e497c86

Browse files
committed
C++17: Replace call_*() helpers with std::apply().
1 parent 9bbb94d commit e497c86

File tree

3 files changed

+4
-45
lines changed

3 files changed

+4
-45
lines changed

sigc++/adaptors/bind.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ struct bind_functor : public adapts<T_functor>
151151
const auto t_end = internal::tuple_end<t_args_size - I_location>(t_args);
152152
const auto t_with_bound = std::tuple_cat(t_start, t_bound, t_end);
153153

154-
constexpr const auto seq =
155-
std::make_index_sequence<std::tuple_size<decltype(t_with_bound)>::value>();
156-
return call_functor_operator_parentheses(t_with_bound, seq);
154+
return std::apply(this->functor_, t_with_bound);
157155
}
158156

159157
/** Constructs a bind_functor object that binds an argument to the passed functor.
@@ -168,12 +166,6 @@ struct bind_functor : public adapts<T_functor>
168166
private:
169167
/// The arguments bound to the functor.
170168
std::tuple<bound_argument<T_bound>...> bound_;
171-
172-
template <typename T, std::size_t... Is>
173-
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
174-
{
175-
return std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
176-
}
177169
};
178170

179171
/** Adaptor that binds argument(s) to the wrapped functor.
@@ -200,8 +192,7 @@ struct bind_functor<-1, T_functor, T_type...> : public adapts<T_functor>
200192
const auto t_bound = internal::tuple_transform_each<internal::TransformEachInvoker>(bound_);
201193
const auto t_with_bound = std::tuple_cat(t_args, t_bound);
202194

203-
constexpr auto seq = std::make_index_sequence<std::tuple_size<decltype(t_with_bound)>::value>();
204-
return call_functor_operator_parentheses(t_with_bound, seq);
195+
return std::apply(this->functor, t_with_bound);
205196
}
206197

207198
/** Constructs a bind_functor object that binds an argument to the passed functor.
@@ -215,13 +206,6 @@ struct bind_functor<-1, T_functor, T_type...> : public adapts<T_functor>
215206

216207
/// The argument bound to the functor.
217208
std::tuple<bound_argument<T_type>...> bound_;
218-
219-
private:
220-
template <typename T, std::size_t... Is>
221-
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
222-
{
223-
return std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
224-
}
225209
};
226210

227211
#ifndef DOXYGEN_SHOULD_SKIP_THIS

sigc++/adaptors/hide.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,13 @@ struct hide_functor : public adapts<T_functor>
102102
const auto t_end = internal::tuple_end<size - index_ignore - 1>(t);
103103
const auto t_used = std::tuple_cat(t_start, t_end);
104104

105-
constexpr auto size_used = size - 1;
106-
107-
// TODO: Remove these? They are just here as a sanity check.
108-
static_assert(std::tuple_size<decltype(t_used)>::value == size_used, "Unexpected t_used size.");
109-
110-
const auto seq = std::make_index_sequence<size_used>();
111-
return call_functor_operator_parentheses(t_used, seq);
105+
return std::apply(this->functor_, t_used);
112106
}
113107

114108
/** Constructs a hide_functor object that adds a dummy parameter to the passed functor.
115109
* @param func Functor to invoke from operator()().
116110
*/
117111
explicit hide_functor(const T_functor& func) : adapts<T_functor>(func) {}
118-
119-
private:
120-
// TODO_variadic: Replace this with std::experimental::apply() if that becomes standard
121-
// C++, or add our own implementation, to avoid code duplication.
122-
template <typename T_tuple, std::size_t... Is>
123-
decltype(auto) call_functor_operator_parentheses(T_tuple& tuple, std::index_sequence<Is...>)
124-
{
125-
return std::invoke(this->functor_, std::get<Is>(tuple)...);
126-
}
127112
};
128113

129114
#ifndef DOXYGEN_SHOULD_SKIP_THIS

sigc++/signal.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ struct signal_emit
246246
*/
247247
T_return operator()(const slot_type& slot) const
248248
{
249-
const auto seq = std::make_index_sequence<std::tuple_size<decltype(a_)>::value>();
250-
return call_call_type_operator_parentheses_with_tuple(slot, a_, seq);
249+
return std::apply(slot, a_);
251250
}
252251

253252
/** Executes a list of slots using an accumulator of type @e T_accumulator.
@@ -274,15 +273,6 @@ struct signal_emit
274273

275274
private:
276275
std::tuple<type_trait_take_t<T_arg>...> a_;
277-
278-
// TODO_variadic: Replace this with std::experimental::apply() if that becomes standard
279-
// C++, or add our own implementation, to avoid code duplication.
280-
template <std::size_t... Is>
281-
decltype(auto) call_call_type_operator_parentheses_with_tuple(
282-
const slot_type& slot, const std::tuple<T_arg...>& tuple, std::index_sequence<Is...>) const
283-
{
284-
return std::invoke(slot, std::get<Is>(tuple)...);
285-
}
286276
};
287277

288278
/** Abstracts signal emission.

0 commit comments

Comments
 (0)