Skip to content

Commit 9bbb94d

Browse files
committed
C++17: Use std::invoke().
This makes code more generic. Maybe this will let us simplify code. I don't actually have a compiler (or its standard library) that supports this, so this probably does not build.
1 parent a05dd26 commit 9bbb94d

File tree

14 files changed

+45
-21
lines changed

14 files changed

+45
-21
lines changed

sigc++/adaptors/adaptor_trait.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <sigc++/functors/ptr_fun.h>
2626
#include <sigc++/functors/mem_fun.h>
2727
#include <sigc++/adaptors/adaptor_base.h>
28+
#include <functional>
2829

2930
/*
3031
* The idea here is simple. To prevent the need to
@@ -87,7 +88,9 @@ struct adaptor_functor : public adaptor_base
8788
/** Invokes the wrapped functor passing on the arguments.
8889
* @return The return value of the functor invocation.
8990
*/
90-
decltype(auto) operator()() const { return functor_(); }
91+
decltype(auto) operator()() const {
92+
std::invoke(functor_);
93+
}
9194

9295
/** Invokes the wrapped functor passing on the arguments.
9396
* @param arg Arguments to be passed on to the functor.
@@ -96,7 +99,7 @@ struct adaptor_functor : public adaptor_base
9699
template <typename... T_arg>
97100
decltype(auto) operator()(T_arg&&... arg) const
98101
{
99-
return functor_(std::forward<T_arg>(arg)...);
102+
return std::invoke(functor_, std::forward<T_arg>(arg)...);
100103
}
101104

102105
/// Constructs an invalid functor.

sigc++/adaptors/bind.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sigc++/tuple-utils/tuple_start.h>
2727
#include <sigc++/tuple-utils/tuple_end.h>
2828
#include <sigc++/tuple-utils/tuple_transform_each.h>
29+
#include <functional>
2930

3031

3132
namespace sigc
@@ -171,7 +172,7 @@ struct bind_functor : public adapts<T_functor>
171172
template <typename T, std::size_t... Is>
172173
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
173174
{
174-
return (this->functor_)(std::get<Is>(std::forward<T>(tuple))...);
175+
return std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
175176
}
176177
};
177178

@@ -219,7 +220,7 @@ struct bind_functor<-1, T_functor, T_type...> : public adapts<T_functor>
219220
template <typename T, std::size_t... Is>
220221
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
221222
{
222-
return (this->functor_)(std::get<Is>(std::forward<T>(tuple))...);
223+
return std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
223224
}
224225
};
225226

sigc++/adaptors/bind_return.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct bind_return_functor : public adapts<T_functor>
4949
template <typename... T_arg>
5050
inline typename unwrap_reference<T_return>::type operator()(T_arg... a)
5151
{
52+
//TODO: Use std::invoke() here?
5253
this->functor_.template operator()<type_trait_pass_t<T_arg>...>(a...);
5354
return ret_value_.invoke();
5455
}
@@ -71,7 +72,7 @@ template <typename T_return, typename T_functor>
7172
typename unwrap_reference<T_return>::type
7273
bind_return_functor<T_return, T_functor>::operator()()
7374
{
74-
this->functor_();
75+
std::invoke(this->functor_);
7576
return ret_value_.invoke();
7677
}
7778

sigc++/adaptors/compose.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef SIGC_ADAPTORS_COMPOSE_H
2020
#define SIGC_ADAPTORS_COMPOSE_H
2121
#include <sigc++/adaptors/adapts.h>
22+
#include <functional>
2223

2324
namespace sigc
2425
{
@@ -61,12 +62,14 @@ namespace sigc
6162
template <typename T_setter, typename T_getter>
6263
struct compose1_functor : public adapts<T_setter>
6364
{
64-
decltype(auto) operator()() { return this->functor_(get_()); }
65+
decltype(auto) operator()() {
66+
return std::invoke(this->functor_, get_());
67+
}
6568

6669
template <typename... T_arg>
6770
decltype(auto) operator()(T_arg&&... a)
6871
{
69-
return this->functor_(get_(std::forward<T_arg>(a)...));
72+
return std::invoke(this->functor_, get_(std::forward<T_arg>(a)...));
7073
}
7174

7275
/** Constructs a compose1_functor object that combines the passed functors.
@@ -95,12 +98,14 @@ struct compose1_functor : public adapts<T_setter>
9598
template <typename T_setter, typename T_getter1, typename T_getter2>
9699
struct compose2_functor : public adapts<T_setter>
97100
{
98-
decltype(auto) operator()() { return this->functor_(get1_(), get2_()); }
101+
decltype(auto) operator()() {
102+
return std::invoke(this->functor_, get1_(), get2_());
103+
}
99104

100105
template <typename... T_arg>
101106
decltype(auto) operator()(T_arg... a)
102107
{
103-
return this->functor_(get1_(a...), get2_(a...));
108+
return std::invoke(this->functor_, get1_(a...), get2_(a...));
104109
}
105110

106111
/** Constructs a compose2_functor object that combines the passed functors.

sigc++/adaptors/exception_catch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct exception_catch_functor : public adapts<T_functor>
8080
{
8181
try
8282
{
83-
return this->functor_();
83+
return std::invoke(this->functor_);
8484
}
8585
catch (...)
8686
{
@@ -93,6 +93,7 @@ struct exception_catch_functor : public adapts<T_functor>
9393
{
9494
try
9595
{
96+
//TODO: Use std::invoke here?
9697
return this->functor_.template operator()<type_trait_pass_t<T_arg>...>(a...);
9798
}
9899
catch (...)

sigc++/adaptors/hide.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct hide_functor : public adapts<T_functor>
122122
template <typename T_tuple, std::size_t... Is>
123123
decltype(auto) call_functor_operator_parentheses(T_tuple& tuple, std::index_sequence<Is...>)
124124
{
125-
return this->functor_.template operator()(std::get<Is>(tuple)...);
125+
return std::invoke(this->functor_, std::get<Is>(tuple)...);
126126
}
127127
};
128128

sigc++/adaptors/retype.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct retype_functor : public adapts<T_functor>
8282
template <typename... T_arg>
8383
decltype(auto) operator()(T_arg... a)
8484
{
85+
//TODO: Use std::invoke() here?
8586
return this->functor_.template operator()<type_trait_take_t<T_type>...>(
8687
static_cast<T_type>(a)...);
8788
}

sigc++/adaptors/retype_return.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct retype_return_functor : public adapts<T_functor>
4141
template <typename... T_arg>
4242
inline T_return operator()(T_arg&&... a)
4343
{
44+
//TODO: Use std::invoke() here?
4445
return T_return(this->functor_.template operator() < T_arg... > (std::forward<T_arg>(a)...));
4546
}
4647

@@ -60,7 +61,7 @@ template <typename T_return, typename T_functor>
6061
T_return
6162
retype_return_functor<T_return, T_functor>::operator()()
6263
{
63-
return T_return(this->functor_());
64+
return T_return(std::invoke(this->functor_));
6465
}
6566

6667
/** Adaptor that performs a C-style cast on the return value of a functor.
@@ -81,6 +82,7 @@ struct retype_return_functor<void, T_functor> : public adapts<T_functor>
8182
template <typename... T_arg>
8283
inline void operator()(T_arg... a)
8384
{
85+
//TODO: Use std::invoke() here?
8486
this->functor_.template operator()<T_arg...>(a...);
8587
}
8688

@@ -92,7 +94,7 @@ template <typename T_functor>
9294
void
9395
retype_return_functor<void, T_functor>::operator()()
9496
{
95-
this->functor_();
97+
std::invoke(this->functor_);
9698
}
9799

98100
#ifndef DOXYGEN_SHOULD_SKIP_THIS

sigc++/adaptors/track_obj.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ class track_obj_functor : public adapts<T_functor>
8383
/** Invokes the wrapped functor.
8484
* @return The return value of the functor invocation.
8585
*/
86-
decltype(auto) operator()() { return this->functor_(); }
86+
decltype(auto) operator()() {
87+
return std::invoke(this->functor_);
88+
}
8789

8890
/** Invokes the wrapped functor passing on the arguments.
8991
* @param arg Arguments to be passed on to the functor.
@@ -92,6 +94,7 @@ class track_obj_functor : public adapts<T_functor>
9294
template <typename... T_arg>
9395
decltype(auto) operator()(T_arg&&... arg)
9496
{
97+
//TODO: Use std::invoke() here?
9598
return this->functor_.template operator()<type_trait_pass_t<T_arg>...>(
9699
std::forward<T_arg>(arg)...);
97100
}

sigc++/functors/mem_fun.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sigc++/type_traits.h>
2222
#include <sigc++/limit_reference.h>
2323
#include <sigc++/member_method_trait.h>
24+
#include <functional>
2425

2526
// implementation notes:
2627
// - we do not use bind here, because it would introduce
@@ -113,7 +114,7 @@ class mem_functor
113114
*/
114115
decltype(auto) operator()(obj_type_with_modifier& obj, type_trait_take_t<T_arg>... a) const
115116
{
116-
return (obj.*func_ptr_)(a...);
117+
return std::invoke(func_ptr_, obj, a...);
117118
}
118119

119120
protected:
@@ -152,7 +153,7 @@ class bound_mem_functor : mem_functor<T_func, T_arg...>
152153
*/
153154
decltype(auto) operator()(type_trait_take_t<T_arg>... a) const
154155
{
155-
return (obj_.invoke().*(this->func_ptr_))(a...);
156+
return std::invoke(this->func_ptr_, obj_, a...);
156157
}
157158

158159
// protected:

sigc++/functors/ptr_fun.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef SIGC_FUNCTORS_PTR_FUN_H
2020
#define SIGC_FUNCTORS_PTR_FUN_H
2121
#include <sigc++/type_traits.h>
22+
#include <functional>
2223

2324
namespace sigc
2425
{
@@ -92,7 +93,9 @@ class pointer_functor<T_return(T_args...)>
9293
* @param a Arguments to be passed on to the function.
9394
* @return The return value of the function invocation.
9495
*/
95-
T_return operator()(type_trait_take_t<T_args>... a) const { return func_ptr_(a...); }
96+
T_return operator()(type_trait_take_t<T_args>... a) const {
97+
return std::invoke(func_ptr_, a...);
98+
}
9699
};
97100

98101
/** Creates a functor of type sigc::pointer_functor which wraps an existing non-member function.

sigc++/functors/slot.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sigc++/visit_each.h>
2424
#include <sigc++/adaptors/adaptor_trait.h>
2525
#include <sigc++/functors/slot_base.h>
26+
#include <functional>
2627

2728
#include <memory>
2829

@@ -191,8 +192,10 @@ class slot<T_return(T_arg...)> : public slot_base
191192
*/
192193
inline T_return operator()(type_trait_take_t<T_arg>... a) const
193194
{
194-
if (!empty() && !blocked())
195-
return (reinterpret_cast<call_type>(slot_base::rep_->call_))(slot_base::rep_, a...);
195+
if (!empty() && !blocked()) {
196+
return std::invoke(reinterpret_cast<call_type>(slot_base::rep_->call_), slot_base::rep_, a...);
197+
}
198+
196199
return T_return();
197200
}
198201

sigc++/signal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ struct signal_emit
281281
decltype(auto) call_call_type_operator_parentheses_with_tuple(
282282
const slot_type& slot, const std::tuple<T_arg...>& tuple, std::index_sequence<Is...>) const
283283
{
284-
return (slot)(std::get<Is>(tuple)...);
284+
return std::invoke(slot, std::get<Is>(tuple)...);
285285
}
286286
};
287287

sigc++/visit_each.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct limit_trackable_target
4444
{
4545
//Only call action_() if T_Type derives from trackable.
4646
if constexpr(is_base_of_or_same_v<sigc::trackable, T_type>) {
47-
action_(type);
47+
std::invoke(action_, type);
4848
}
4949
}
5050

0 commit comments

Comments
 (0)