[libsigcplusplus/variadic_mem_fun3: 1/148] C++11: ptr_fun.h: Replace generated pointer_functor1/2/3/etc with pointer_functor.



commit 5bb10b568a07a35e1c092276b0612d9992bd25b9
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Aug 14 11:27:12 2015 +0200

    C++11: ptr_fun.h: Replace generated pointer_functor1/2/3/etc with pointer_functor.
    
    Using C++11 variadic templates arguments.
    Note that T_Return is now the first template parameter, so that the variadic
    parameters can be the trailing parameters, as in std::function.

 sigc++/adaptors/macros/retype.h.m4        |    6 +-
 sigc++/functors/macros/functor_trait.h.m4 |    7 ++-
 sigc++/functors/macros/ptr_fun.h.m4       |   80 +++++++++++++---------------
 tests/test_slot_disconnect.cc             |    2 +-
 4 files changed, 46 insertions(+), 49 deletions(-)
---
diff --git a/sigc++/adaptors/macros/retype.h.m4 b/sigc++/adaptors/macros/retype.h.m4
index 8267c81..0f3ab41 100644
--- a/sigc++/adaptors/macros/retype.h.m4
+++ b/sigc++/adaptors/macros/retype.h.m4
@@ -51,9 +51,9 @@ define([RETYPE_POINTER_FUNCTOR],[dnl
  * @ingroup retype
  */
 template <LIST(LOOP(class T_arg%1, $1), class T_return)>
-inline retype_functor<LIST(pointer_functor$1<LIST(LOOP(T_arg%1, $1), T_return)>, LOOP(T_arg%1, $1)) >
-retype(const pointer_functor$1<LIST(LOOP(T_arg%1, $1), T_return)>& _A_functor)
-{ return retype_functor<LIST(pointer_functor$1<LIST(LOOP(T_arg%1, $1), T_return)>, LOOP(T_arg%1, $1)) >
+inline retype_functor<LIST(pointer_functor<LIST(T_return, LOOP(T_arg%1, $1))>, LOOP(T_arg%1, $1)) >
+retype(const pointer_functor<LIST(T_return, LOOP(T_arg%1, $1))>& _A_functor)
+{ return retype_functor<LIST(pointer_functor<LIST(T_return, LOOP(T_arg%1, $1))>, LOOP(T_arg%1, $1)) >
     (_A_functor); }
 
 ])
diff --git a/sigc++/functors/macros/functor_trait.h.m4 b/sigc++/functors/macros/functor_trait.h.m4
index 59a9b9b..4c9d613 100644
--- a/sigc++/functors/macros/functor_trait.h.m4
+++ b/sigc++/functors/macros/functor_trait.h.m4
@@ -18,12 +18,11 @@ divert(-1)
 include(template.macros.m4)
 
 define([FUNCTOR_PTR_FUN],[dnl
-template <LIST(LOOP(class T_arg%1, $1), class T_return)> class pointer_functor$1;
 template <LIST(LOOP(class T_arg%1, $1), class T_return)>
 struct functor_trait<T_return (*)(LOOP(T_arg%1, $1)), false, false>
 {
   typedef T_return result_type;
-  typedef pointer_functor$1<LIST(LOOP(T_arg%1, $1), T_return)> functor_type;
+  typedef pointer_functor<LIST(T_return, LOOP(T_arg%1, $1))> functor_type;
 };
 
 ])
@@ -270,6 +269,10 @@ struct functor_trait<T_functor, false, true>   \
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 // detect the return type and the functor version of non-functor types.
+
+template <class T_return, class... T_args>
+class pointer_functor;
+
 FOR(0,CALL_SIZE,[[FUNCTOR_PTR_FUN(%1)]])
 FOR(0,CALL_SIZE,[[FUNCTOR_MEM_FUN(%1)]])
 #endif // DOXYGEN_SHOULD_SKIP_THIS
diff --git a/sigc++/functors/macros/ptr_fun.h.m4 b/sigc++/functors/macros/ptr_fun.h.m4
index 355b01c..cb84982 100644
--- a/sigc++/functors/macros/ptr_fun.h.m4
+++ b/sigc++/functors/macros/ptr_fun.h.m4
@@ -18,56 +18,17 @@ divert(-1)
 
 include(template.macros.m4)
 
-define([POINTER_FUNCTOR],[dnl
-/** pointer_functor$1 wraps existing non-member functions with $1 argument(s).
- * Use the convenience function ptr_fun() to create an instance of pointer_functor$1.
- *
- * The following template arguments are used:dnl
-FOR(1,$1,[
- * - @e T_arg%1 Argument type used in the definition of operator()().])
- * - @e T_return The return type of operator()().
- *
- * @ingroup ptr_fun
- */
-template <LIST(LOOP(class T_arg%1, $1), class T_return)>
-class pointer_functor$1 : public functor_base
-{
-  typedef T_return (*function_type)(LOOP(T_arg%1, $1));
-protected: 
-  function_type func_ptr_;
-public:
-  typedef T_return result_type;
-
-  /// Constructs an invalid functor.
-  pointer_functor$1() {}
-
-  /** Constructs a pointer_functor$1 object that wraps an existing function.
-   * @param _A_func Pointer to function that will be invoked from operator()().
-   */
-  explicit pointer_functor$1(function_type _A_func): func_ptr_(_A_func) {}
-
-  /** Execute the wrapped function.dnl
-FOR(1, $1,[
-   * @param _A_a%1 Argument to be passed on to the function.])
-   * @return The return value of the function invocation.
-   */
-  T_return operator()(LOOP(type_trait_take_t<T_arg%1> _A_a%1, $1)) const 
-    { return func_ptr_(LOOP(_A_a%1, $1)); }
-};
-
-])
-
 define([PTR_FUN],[dnl
-/** Creates a functor of type sigc::pointer_functor$1 which wraps an existing non-member function.
+/** 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$1<LIST(LOOP(T_arg%1, $1), 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$1<LIST(LOOP(T_arg%1, $1), T_return)>(_A_func); }
+{ return pointer_functor<LIST(T_return, LOOP(T_arg%1, $1))>(_A_func); }
 
 ])
 
@@ -115,7 +76,40 @@ namespace sigc {
  * @ingroup sigcfunctors
  */
 
-FOR(0,CALL_SIZE,[[POINTER_FUNCTOR(%1)]])dnl
+/** pointer_functor wraps existing non-member functions with, or without, arguments.
+ * Use the convenience function ptr_fun() to create an instance of pointer_functor.
+ *
+ * The following template arguments are used:
+ * - @e T_args... Argument types used in the definition of operator()().
+ * - @e T_return The return type of operator()().
+ *
+ * @ingroup ptr_fun
+ */
+template <class T_return, class... T_args>
+class pointer_functor : public functor_base
+{
+  using function_type = T_return (*)(T_args...);
+protected: 
+  function_type func_ptr_;
+public:
+  using result_type = T_return;
+
+  /// Constructs an invalid functor.
+  pointer_functor() {}
+
+  /** Constructs a pointer_functor2 object that wraps an existing function.
+   * @param _A_func Pointer to function that will be invoked from operator()().
+   */
+  explicit pointer_functor(function_type _A_func): func_ptr_(_A_func) {}
+
+  /** Execute the wrapped function.
+   * @param _A_a1 Argument to be passed on to the function.
+   * @param _A_a2 Argument 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_a) const 
+    { return func_ptr_(_A_a...); }
+};
 
 // numbered ptr_fun
 FOR(0,CALL_SIZE,[[PTR_FUN(%1)]])dnl
diff --git a/tests/test_slot_disconnect.cc b/tests/test_slot_disconnect.cc
index 4044135..232066b 100644
--- a/tests/test_slot_disconnect.cc
+++ b/tests/test_slot_disconnect.cc
@@ -31,7 +31,7 @@ int main(int argc, char* argv[])
   if (!util->check_command_args(argc, argv))
     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
 
-  //Note that sigc::ptr_fun() creates a sigc::pointer_functor0.
+  //Note that sigc::ptr_fun() creates a sig::pointer_functor.
   sigc::slot<void> theSlot(sigc::ptr_fun(&Foo));
   theSlot();
   util->check_result(result_stream, "Foo");


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