Skip to content

Commit f3da00b

Browse files
committed
C++17: Use std::invoke().
This makes code more generic. Maybe this will let us simplify code.
1 parent 5a4164b commit f3da00b

File tree

12 files changed

+39
-16
lines changed

12 files changed

+39
-16
lines changed

sigc++/adaptors/adaptor_trait.h

Lines changed: 2 additions & 1 deletion
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
@@ -96,7 +97,7 @@ struct adaptor_functor : public adaptor_base
9697
template <typename... T_arg>
9798
decltype(auto) operator()(T_arg&&... arg) const
9899
{
99-
return functor_(std::forward<T_arg>(arg)...);
100+
return std::invoke(functor_, std::forward<T_arg>(arg)...);
100101
}
101102

102103
/// Constructs an invalid functor.

sigc++/adaptors/bind.h

Lines changed: 1 addition & 0 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

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/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_.invoke(), 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.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy