diff options
author | Slava Andrejev <vyac.andrejev@gmail.com> | 2021-12-22 21:19:45 -0800 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2021-12-23 10:18:18 +0100 |
commit | cc857baa5aac41f5731e92d2da276826481a4631 (patch) | |
tree | e9caf94ccfb0a278072d0aa0ac1542787a6b83ef | |
parent | a4883790100b0da6f777ec154a525389f776a3c7 (diff) | |
download | sigc++-cc857baa5aac41f5731e92d2da276826481a4631.tar.gz |
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.
-rw-r--r-- | sigc++/functors/mem_fun.h | 2 | ||||
-rw-r--r-- | sigc++/functors/ptr_fun.h | 4 | ||||
-rw-r--r-- | tests/test_rvalue_ref.cc | 26 |
3 files changed, 30 insertions, 2 deletions
diff --git a/sigc++/functors/mem_fun.h b/sigc++/functors/mem_fun.h index e3327fb..1b74c3d 100644 --- a/sigc++/functors/mem_fun.h +++ b/sigc++/functors/mem_fun.h @@ -113,7 +113,7 @@ public: */ decltype(auto) operator()(obj_type_with_modifier& obj, type_trait_take_t<T_arg>... a) const { - return std::invoke(func_ptr_, obj, a...); + return std::invoke(func_ptr_, obj, std::forward<type_trait_take_t<T_arg>>(a)...); } protected: diff --git a/sigc++/functors/ptr_fun.h b/sigc++/functors/ptr_fun.h index 288ac87..c1dc8b7 100644 --- a/sigc++/functors/ptr_fun.h +++ b/sigc++/functors/ptr_fun.h @@ -92,7 +92,9 @@ public: * @param a Arguments to be passed on to the function. * @return The return value of the function invocation. */ - T_return operator()(type_trait_take_t<T_args>... a) const { return std::invoke(func_ptr_, a...); } + T_return operator()(type_trait_take_t<T_args>... a) const { + return std::invoke(func_ptr_, std::forward<type_trait_take_t<T_args>>(a)...); + } }; /** Creates a functor of type sigc::pointer_functor which wraps an existing non-member function. diff --git a/tests/test_rvalue_ref.cc b/tests/test_rvalue_ref.cc index ec81d39..4e1666b 100644 --- a/tests/test_rvalue_ref.cc +++ b/tests/test_rvalue_ref.cc @@ -21,6 +21,9 @@ struct A void foo(MoveableStruct &&) { result_stream << "A::foo(MoveableStruct&&)"; } }; +void boo(MoveableStruct &&) { + result_stream << "boo(MoveableStruct&&)"; +} } // end anonymous namespace @@ -49,6 +52,17 @@ test_slot() void test_mem_fun() { + sigc::slot<void(A &, MoveableStruct &&)> slot; + A a; + slot = sigc::mem_fun(&A::foo); + MoveableStruct x; + slot(a, std::move(x)); + util->check_result(result_stream, "A::foo(MoveableStruct&&)"); +} + +void +test_bound_mem_fun() +{ sigc::slot<void(MoveableStruct &&)> slot; A a; slot = sigc::mem_fun(a, &A::foo); @@ -57,6 +71,16 @@ test_mem_fun() util->check_result(result_stream, "A::foo(MoveableStruct&&)"); } +void +test_ptr_fun() +{ + sigc::slot<void(MoveableStruct &&)> slot; + slot = sigc::ptr_fun(&boo); + MoveableStruct x; + slot(std::move(x)); + util->check_result(result_stream, "boo(MoveableStruct&&)"); +} + int main(int argc, char* argv[]) { @@ -66,7 +90,9 @@ main(int argc, char* argv[]) test_signal(); test_slot(); + test_bound_mem_fun(); test_mem_fun(); + test_ptr_fun(); return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE; } // end main() |