Skip to content

Commit cc857ba

Browse files
slavaandrejevkjellahl
authored andcommitted
Add missing perfect forwarding in mem_functor and pointer_functor
This is a missed addition to the commit that allowed rvalue references in slot parameters.
1 parent a488379 commit cc857ba

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

sigc++/functors/mem_fun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class mem_functor
113113
*/
114114
decltype(auto) operator()(obj_type_with_modifier& obj, type_trait_take_t<T_arg>... a) const
115115
{
116-
return std::invoke(func_ptr_, obj, a...);
116+
return std::invoke(func_ptr_, obj, std::forward<type_trait_take_t<T_arg>>(a)...);
117117
}
118118

119119
protected:

sigc++/functors/ptr_fun.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class pointer_functor<T_return(T_args...)>
9292
* @param a Arguments to be passed on to the function.
9393
* @return The return value of the function invocation.
9494
*/
95-
T_return operator()(type_trait_take_t<T_args>... a) const { return std::invoke(func_ptr_, a...); }
95+
T_return operator()(type_trait_take_t<T_args>... a) const {
96+
return std::invoke(func_ptr_, std::forward<type_trait_take_t<T_args>>(a)...);
97+
}
9698
};
9799

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

tests/test_rvalue_ref.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ struct A
2121
void foo(MoveableStruct &&) { result_stream << "A::foo(MoveableStruct&&)"; }
2222
};
2323

24+
void boo(MoveableStruct &&) {
25+
result_stream << "boo(MoveableStruct&&)";
26+
}
2427

2528
} // end anonymous namespace
2629

@@ -48,6 +51,17 @@ test_slot()
4851

4952
void
5053
test_mem_fun()
54+
{
55+
sigc::slot<void(A &, MoveableStruct &&)> slot;
56+
A a;
57+
slot = sigc::mem_fun(&A::foo);
58+
MoveableStruct x;
59+
slot(a, std::move(x));
60+
util->check_result(result_stream, "A::foo(MoveableStruct&&)");
61+
}
62+
63+
void
64+
test_bound_mem_fun()
5165
{
5266
sigc::slot<void(MoveableStruct &&)> slot;
5367
A a;
@@ -57,6 +71,16 @@ test_mem_fun()
5771
util->check_result(result_stream, "A::foo(MoveableStruct&&)");
5872
}
5973

74+
void
75+
test_ptr_fun()
76+
{
77+
sigc::slot<void(MoveableStruct &&)> slot;
78+
slot = sigc::ptr_fun(&boo);
79+
MoveableStruct x;
80+
slot(std::move(x));
81+
util->check_result(result_stream, "boo(MoveableStruct&&)");
82+
}
83+
6084
int
6185
main(int argc, char* argv[])
6286
{
@@ -66,7 +90,9 @@ main(int argc, char* argv[])
6690

6791
test_signal();
6892
test_slot();
93+
test_bound_mem_fun();
6994
test_mem_fun();
95+
test_ptr_fun();
7096

7197
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
7298
} // end main()

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