[libsigc++2/variadic: 2/6] C++11: ptr_fun.h: Replace generated ptr_fun1/2/3/etc with ptr_fun<>.



commit bba0c8dca282a5451653be19d73d0543a2443d02
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Aug 14 11:57:17 2015 +0200

    C++11: ptr_fun.h: Replace generated ptr_fun1/2/3/etc with ptr_fun<>.
    
    Note that T_Return must now be the first parameter, so that the
    variadic template parameters may be trailing, and this means that
    the return type must now be specified if you specify any argument
    types.
    For instance:
      ptr_fun<type_arg1>(&somefunc)
    now becomes
      ptr_fun<void, type_arg2>(&somefunc)
    
    and
      ptr_fun<type_arg1, type_return>(&somefunc)
    now becomes
      ptr_fun<type_return, type_arg1>(&somefunc)
    
    which might be an annoying API change, even though most people just
    use ptr_fun().
    
    However, this breaks the tests:
    
    test_ptr_fun.cc: In function ‘int main(int, char**)’:
    test_ptr_fun.cc:64:21: error: no matches converting function ‘foo’ to type ‘void (*)()’
       sigc::ptr_fun(&foo)();
                         ^
    test_ptr_fun.cc:24:6: note: candidates are: void {anonymous}::foo(int)
     void foo(int i1)
          ^
    test_ptr_fun.cc:18:5: note:                 int {anonymous}::foo()
     int foo()
         ^

 sigc++/functors/macros/ptr_fun.h.m4 |   33 +++++++++++----------------------
 tests/test_accumulated.cc           |    8 ++++----
 tests/test_disconnect.cc            |    4 ++--
 tests/test_functor_trait.cc         |    6 +++---
 tests/test_ptr_fun.cc               |   12 ++++++------
 tests/test_signal.cc                |    6 +++---
 6 files changed, 29 insertions(+), 40 deletions(-)
---
diff --git a/sigc++/functors/macros/ptr_fun.h.m4 b/sigc++/functors/macros/ptr_fun.h.m4
index cb84982..7c407a2 100644
--- a/sigc++/functors/macros/ptr_fun.h.m4
+++ b/sigc++/functors/macros/ptr_fun.h.m4
@@ -18,20 +18,6 @@ divert(-1)
 
 include(template.macros.m4)
 
-define([PTR_FUN],[dnl
-/** Creates a functor of type sigc::pointer_functor which wraps an existing non-member function.
- * @param _A_func Pointer to function that should be wrapped.
- * @return Functor that executes @e _A_func on invokation.
- *
- * @ingroup ptr_fun
- */
-template <LIST(LOOP(class T_arg%1, $1), class T_return)>
-inline pointer_functor<LIST(T_return, LOOP(T_arg%1, $1))> 
-ptr_fun[]ifelse($2,, $1)(T_return (*_A_func)(LOOP(T_arg%1,$1)))
-{ return pointer_functor<LIST(T_return, LOOP(T_arg%1, $1))>(_A_func); }
-
-])
-
 divert(0)
 _FIREWALL([FUNCTORS_PTR_FUN])
 #include <sigc++/type_traits.h>
@@ -51,14 +37,12 @@ namespace sigc {
  * sigc::slot<void, int> sl = sigc::ptr_fun(&foo);
  * @endcode
  *
- * Use ptr_fun#() if there is an ambiguity as to the number of arguments.
- *
  * @par Example:
  * @code
  * void foo(int) {}  // choose this one
  * void foo(float) {}
  * void foo(int, int) {}
- * sigc::slot<void, long> sl = sigc::ptr_fun1<int>(&foo);
+ * sigc::slot<void, long> sl = sigc::ptr_fun<void, int>(&foo);
  * @endcode
  *
  * ptr_fun() can also be used to convert a pointer to a static member
@@ -111,10 +95,15 @@ public:
     { return func_ptr_(_A_a...); }
 };
 
-// numbered ptr_fun
-FOR(0,CALL_SIZE,[[PTR_FUN(%1)]])dnl
-
-// unnumbered ptr_fun
-FOR(0,CALL_SIZE,[[PTR_FUN(%1,1)]])dnl
+/** Creates a functor of type sigc::pointer_functor which wraps an existing non-member function.
+ * @param _A_func Pointer to function that should be wrapped.
+ * @return Functor that executes @e _A_func on invokation.
+ *
+ * @ingroup ptr_fun
+ */
+template <class T_return, class... T_args>
+inline pointer_functor<T_return, T_args...> 
+ptr_fun(T_return (*_A_func)(T_args...))
+{ return pointer_functor<T_return, T_args...>(_A_func); }
 
 } /* namespace sigc */
diff --git a/tests/test_accumulated.cc b/tests/test_accumulated.cc
index adbc295..06e6606 100644
--- a/tests/test_accumulated.cc
+++ b/tests/test_accumulated.cc
@@ -88,13 +88,13 @@ int main(int argc, char* argv[])
   util->check_result(result_stream, "Vector result (empty slot list): empty");
 
   A a;
-  sig.connect(sigc::ptr_fun1(&foo));
+  sig.connect(sigc::ptr_fun(&foo));
   sig.connect(sigc::mem_fun1(&a, &A::foo));
-  sig.connect(sigc::ptr_fun1(&bar));
+  sig.connect(sigc::ptr_fun(&bar));
 
-  sig_vec.connect(sigc::ptr_fun1(&foo));
+  sig_vec.connect(sigc::ptr_fun(&foo));
   sig_vec.connect(sigc::mem_fun1(&a, &A::foo));
-  sig_vec.connect(sigc::ptr_fun1(&bar));
+  sig_vec.connect(sigc::ptr_fun(&bar));
 
   double dres = sig(1);
   result_stream << "Mean accumulator: Result (i=1): "
diff --git a/tests/test_disconnect.cc b/tests/test_disconnect.cc
index 048acbd..0c11765 100644
--- a/tests/test_disconnect.cc
+++ b/tests/test_disconnect.cc
@@ -90,8 +90,8 @@ int main(int argc, char* argv[])
   {
     A a;
     sig.connect(sigc::mem_fun1(&a, &A::foo));
-    confoo = sig.connect(sigc::ptr_fun1(&foo));
-    conbar = sig.connect(sigc::ptr_fun1(&bar));
+    confoo = sig.connect(sigc::ptr_fun(&foo));
+    conbar = sig.connect(sigc::ptr_fun(&bar));
     result_stream << "sig is connected to A::foo, foo, bar (size=" << sig.size() << "): ";
     sig(1);
     util->check_result(result_stream,
diff --git a/tests/test_functor_trait.cc b/tests/test_functor_trait.cc
index bf3b26e..1031845 100644
--- a/tests/test_functor_trait.cc
+++ b/tests/test_functor_trait.cc
@@ -83,15 +83,15 @@ int main(int argc, char* argv[])
   int k = 3;
   A a;
   result_stream << "hit all targets: ";
-  sigc::visit_each(print(), sigc::compose(sigc::bind(sigc::ptr_fun3(&foo), sigc::ref(a), i), 
sigc::ptr_fun1(&bar)));
+  sigc::visit_each(print(), sigc::compose(sigc::bind(sigc::ptr_fun(&foo), sigc::ref(a), i), 
sigc::ptr_fun(&bar)));
   util->check_result(result_stream, "hit all targets: other trackable int: 1 other ");
 
   result_stream << "hit all ints: ";
-  sigc::visit_each_type<int>(print(), sigc::compose(sigc::bind(sigc::ptr_fun3(&foo), sigc::ref(a), 
j),sigc::ptr_fun1(&bar)));
+  sigc::visit_each_type<int>(print(), sigc::compose(sigc::bind(sigc::ptr_fun(&foo), sigc::ref(a), 
j),sigc::ptr_fun(&bar)));
   util->check_result(result_stream, "hit all ints: int: 2 ");
 
   result_stream << "hit all trackable: ";
-  sigc::visit_each_type<trackable>(print(), sigc::compose(sigc::bind(sigc::ptr_fun3(&foo), sigc::ref(a), 
k),sigc::ptr_fun1(&bar)));
+  sigc::visit_each_type<trackable>(print(), sigc::compose(sigc::bind(sigc::ptr_fun(&foo), sigc::ref(a), 
k),sigc::ptr_fun(&bar)));
   util->check_result(result_stream, "hit all trackable: trackable ");
 
   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/test_ptr_fun.cc b/tests/test_ptr_fun.cc
index d3cbf51..1784aed 100644
--- a/tests/test_ptr_fun.cc
+++ b/tests/test_ptr_fun.cc
@@ -61,24 +61,24 @@ int main(int argc, char* argv[])
   if (!util->check_command_args(argc, argv))
     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
 
-  sigc::ptr_fun0(&foo)();
+  sigc::ptr_fun(&foo)();
   util->check_result(result_stream, "foo()");
 
-  sigc::ptr_fun1(&foo)(1);
+  sigc::ptr_fun(&foo)(1);
   util->check_result(result_stream, "foo(int 1)");
 
 #if ENABLE_TEST_OF_OVERLOADED_FUNCTIONS
-  sigc::ptr_fun1<char>(&bar)(2);
+  sigc::ptr_fun<void, char>(&bar)(2);
   util->check_result(result_stream, "bar(char 2)");
 
-  sigc::ptr_fun1<float>(&bar)(2.0f);
+  sigc::ptr_fun<void, float>(&bar)(2.0f);
   util->check_result(result_stream, "bar(float 2)");
 #else
-  sigc::ptr_fun1(&bar)(2.0f);
+  sigc::ptr_fun(&bar)(2.0f);
   util->check_result(result_stream, "bar(float 2)");
 #endif
 
-  sigc::ptr_fun2(&bar)(3, 5);
+  sigc::ptr_fun(&bar)(3, 5);
   util->check_result(result_stream, "bar(int 3, int 5)");
 
   sigc::ptr_fun(&test::foo)();
diff --git a/tests/test_signal.cc b/tests/test_signal.cc
index 163eb11..c8086be 100644
--- a/tests/test_signal.cc
+++ b/tests/test_signal.cc
@@ -61,9 +61,9 @@ int main(int argc, char* argv[])
   // connect some slots before emitting & test auto-disconnection
   {
     A a;
-    sig.connect(sigc::ptr_fun1(&foo));
+    sig.connect(sigc::ptr_fun(&foo));
     sig.connect(sigc::mem_fun1(&a, &A::foo));
-    sig.connect(sigc::ptr_fun1(&bar));
+    sig.connect(sigc::ptr_fun(&bar));
     sig(1);
     result_stream << sig.size();
     util->check_result(result_stream, "foo(int 1) A::foo(int 1) bar(float 1) 3");
@@ -84,7 +84,7 @@ int main(int argc, char* argv[])
   util->check_result(result_stream, "A::foo(string 'guest book') foo was here");
 
   // test make_slot()
-  sig.connect(sigc::ptr_fun1(&foo));
+  sig.connect(sigc::ptr_fun(&foo));
   sigc::signal<int,int> sig2;
   sig2.connect(sig.make_slot());
   sig2(3);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]