From cc857baa5aac41f5731e92d2da276826481a4631 Mon Sep 17 00:00:00 2001 From: Slava Andrejev Date: Wed, 22 Dec 2021 21:19:45 -0800 Subject: 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. --- sigc++/functors/mem_fun.h | 2 +- sigc++/functors/ptr_fun.h | 4 +++- 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... a) const { - return std::invoke(func_ptr_, obj, a...); + return std::invoke(func_ptr_, obj, std::forward>(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... a) const { return std::invoke(func_ptr_, a...); } + T_return operator()(type_trait_take_t... a) const { + return std::invoke(func_ptr_, std::forward>(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 @@ -48,6 +51,17 @@ test_slot() void test_mem_fun() +{ + sigc::slot 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 slot; A a; @@ -57,6 +71,16 @@ test_mem_fun() util->check_result(result_stream, "A::foo(MoveableStruct&&)"); } +void +test_ptr_fun() +{ + sigc::slot 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() -- cgit v1.2.1