c++-gtk-utils
callback.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 to 2016 Chris Vine
2 
3 The library comprised in this file or of which this file is part is
4 distributed by Chris Vine under the GNU Lesser General Public
5 License as follows:
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public License
9  as published by the Free Software Foundation; either version 2.1 of
10  the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License, version 2.1, for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License, version 2.1, along with this library (see the file LGPL.TXT
19  which came with this source code package in the c++-gtk-utils
20  sub-directory); if not, write to the Free Software Foundation, Inc.,
21  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 
23 However, it is not intended that the object code of a program whose
24 source code instantiates a template from this file or uses macros or
25 inline functions (of any length) should by reason only of that
26 instantiation or use be subject to the restrictions of use in the GNU
27 Lesser General Public License. With that in mind, the words "and
28 macros, inline functions and instantiations of templates (of any
29 length)" shall be treated as substituted for the words "and small
30 macros and small inline functions (ten lines or less in length)" in
31 the fourth paragraph of section 5 of that licence. This does not
32 affect any other reason why object code may be subject to the
33 restrictions in that licence (nor for the avoidance of doubt does it
34 affect the application of section 2 of that licence to modifications
35 of the source code in this file).
36 
37 */
38 
39 #ifndef CGU_CALLBACK_H
40 #define CGU_CALLBACK_H
41 
42 /**
43  * @file callback.h
44  * @brief This file provides classes for type erasure.
45  *
46  * \#include <c++-gtk-utils/callback.h>
47  *
48  * These classes provide type erasure on callable objects. They
49  * comprise a generic callback creation and execution interface for
50  * closures. There is a basic Callback::Callback type, which is an
51  * entire closure or 'thunk', where all values are bound into the
52  * object, and is completely opaque. Callback::CallbackArg<T...> is a
53  * class which takes unbound arguments of the template types when the
54  * object is dispatched. (The opaque Callback::Callback type is a
55  * typedef for Callback::CallbackArg<>: the two types are
56  * interchangeable.)
57  *
58  * Objects of these classes are normally constructed using the
59  * Callback::lambda() factory function, which takes any callable
60  * object such as a lambda expression or the return value of
61  * std::bind, and returns a pointer to a Callback/CallbackArg object
62  * allocated on free store. When using Callback::lambda(), the
63  * unbound argument types (if any) must be passed as explicit template
64  * parameters.
65  *
66  * Callback/CallbackArg objects can also be constructed using the
67  * Callback::make() and Callback::make_ref() factory functions, which
68  * can be useful where invoking standalone functions or object
69  * methods.
70  *
71  * From version 2.2.6, a convenience Callback::to_unique() function is
72  * available which will construct a std::unique_ptr object from a
73  * Callback/CallbackArg object returned by Callback::lambda(),
74  * Callback::make() or Callback::make_ref(), for the purpose of taking
75  * ownership of the Callback/CallbackArg object. This function is
76  * mainly intended for use with the auto keyword, to avoid having to
77  * write out the type of the unique_ptr object in longhand.
78  * Corresponding Callback::to_functor() and
79  * Callback::to_safe_functor() functions are also provided.
80  *
81  * The Callback/CallbackArg classes do not provide for a return
82  * value. If a result is wanted, users should pass an unbound argument
83  * by reference or pointer (or pointer to pointer).
84  *
85  * The Callback::make() and Callback::make_ref() functions
86  * -------------------------------------------------------
87  *
88  * The Callback::make() and Callback::make_ref() functions construct a
89  * Callback/CallbackArg object from a function pointer (or an object
90  * reference and member function pointer) together with bound
91  * arguments. They provide for a maximum of five bound arguments, and
92  * the unbound arguments (if any) must be the last (trailing)
93  * arguments of the relevant function or method to be called. From
94  * version 2.2.10, if a suitable compiler is used (gcc >= 4.8 or clang
95  * >= 3.4), up to ten bound arguments are permitted - see further
96  * below.
97  *
98  * Callback::make() does a direct type mapping from the bound
99  * arguments of the function or method represented by the callback
100  * object to the arguments stored by it and is for use when all bound
101  * arguments are simple fundamental types such as pointers (including
102  * C strings), integers or floating points.
103  *
104  * Callback::make_ref() is for use where bound arguments include class
105  * types or one or more of the types of the bound arguments include a
106  * const reference. It will accomplish perfect forwarding (by lvalue
107  * reference or rvalue reference) when constructing the callback and
108  * will also ensure that a copy of any object to be passed by const
109  * reference (as well as any taken by value) is kept in order to avoid
110  * dangling references. Note however that where a member function is
111  * called, the object of which the target function is a member must
112  * still be in existence when the Callback/CallbackArg object is
113  * dispatched and, unlike Callback::make(), Callback::make_ref()
114  * cannot be used with overloaded functions except with explicit
115  * disambiguation.
116  *
117  * Callback::make() can also construct a Callback/CallbackArg object
118  * from a std::function object.
119  *
120  * As mentioned above, from version 2.2.10 if a suitable compiler is
121  * used (gcc >= 4.8 or clang >= 3.4), up to ten bound arguments are
122  * permitted instead of the previous maximum of five, by using a
123  * std::tuple backend for relevant callback classes. The tuple
124  * backend can be explicitly disabled with the \--without-tuple
125  * configuration option (and it is implicitly disabled with gcc-4.6
126  * and gcc-4.7), in which case the former backend employing the
127  * implementation used prior to version 2.2.10 is retained. For
128  * compilers other than gcc and clang which adequately support
129  * std::tuple, the tuple backend can be manually selected with the
130  * \--with-tuple configuration option in place of the former backend.
131  * Both backends are ABI compatible, because for closure/callback
132  * implementation this library only exports the CallbackArg pure
133  * virtual class.
134  *
135  * Callback::FunctorArg and Callback::SafeFunctorArg classes
136  * ---------------------------------------------------------
137  *
138  * Functor/FunctorArg objects hold a Callback/CallbackArg object by
139  * SharedPtr to enable them to be shared by reference counting, and
140  * SafeFunctor/SafeFunctorArg objects hold them by SharedLockPtr,
141  * which have a thread safe reference count so that they may be shared
142  * between different threads. These classes also have an operator()()
143  * method so as to be callable with function syntax.
144  *
145  * Memory allocation
146  * -----------------
147  *
148  * If the library is installed using the
149  * \--with-glib-memory-slices-no-compat configuration option, any
150  * Callback/CallbackArg object will be constructed in glib memory
151  * slices rather than in the generic C++ free store.
152  *
153  * Usage
154  * -----
155  *
156  * Using Callback::lambda():
157  *
158  * @code
159  * using namespace Cgu;
160  *
161  * // here cb1 is of type Callback::Callback*
162  * auto cb1 = Callback::lambda<>([]() {std::cout << "Hello world\n";});
163  * cb1->dispatch();
164  * delete cb1;
165  *
166  * // here Callback::to_unique() is used to make a std::unique_ptr object to
167  * // manage the callback. cb2 is of type std::unique_ptr<const Callback::Callback>
168  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {std::cout << "Hello world\n";}));
169  * cb2->dispatch();
170  *
171  * // the same using Callback::Functor
172  * Callback::Functor f1{Callback::lambda<>([]() {std::cout << "Hello world\n";})};
173  * f1();
174  *
175  * int k = 5;
176  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, int&>>
177  * auto cb3 = Callback::to_unique(Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;}));
178  * int res;
179  * cb3->dispatch(2, res);
180  * std::cout << k << " times 10 times 2 is " << res << '\n';
181  *
182  * // the same using Callback::FunctorArg
183  * Callback::FunctorArg<int, int&> f2{Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;})};
184  * f2(2, res);
185  * std::cout << k << " times 10 times 2 is " << res << '\n';
186  * @endcode
187  *
188  * Using Callback::make(), with a class object my_obj of type MyClass,
189  * with a method void MyClass::my_method(int, int, const char*):
190  *
191  * @code
192  * using namespace Cgu;
193  *
194  * int arg1 = 1, arg2 = 5;
195  *
196  * // here cb1 is of type Callback::Callback*
197  * auto cb1 = Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n");
198  * cb1->dispatch();
199  * delete cb1;
200  *
201  * // here cb2 is of type std::unique_ptr<const Callback::Callback>
202  * auto cb2 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n"));
203  * cb2->dispatch();
204  *
205  * // the same using Callback::Functor
206  * Callback::Functor f1{Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n")};
207  * f1();
208  *
209  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, const char*>>
210  * auto cb3 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1));
211  * cb3->dispatch(arg2, "Hello\n");
212  *
213  * // the same using Callback::FunctorArg
214  * Callback::FunctorArg<int, const char*> f2{Callback::make(my_obj, &MyClass::my_method, arg1)};
215  * f2(arg2, "Hello\n");
216  * @endcode
217  *
218  * Using Callback::make_ref(), with a class object my_obj of type
219  * MyClass, with a method void MyClass::my_method(int, const
220  * Something&):
221  *
222  * @code
223  * int arg1 = 1;
224  * Something arg2;
225  * // here cb is of type std::unique_ptr<const Callback::Callback>
226  * auto cb = Callback::to_unique(Callback::make_ref(my_obj, &MyClass::my_method, arg1, arg2));
227  * @endcode
228  *
229  * Posting of callbacks
230  * --------------------
231  *
232  * This file also provides a Callback::post() function which will
233  * execute a callback in a glib main loop and can be used (amongst
234  * other things) to pass an event from a worker thread to the main
235  * program thread. In that respect, it provides an alternative to the
236  * Notifier class. It is passed either a pointer to a
237  * Callback::Callback object created with a call to Callback::lambda()
238  * (or Callback::make() or Callback::make_ref()), or it can be passed
239  * a callable object and the implementation will call
240  * Callback::lambda() for you.
241  *
242  * To provide for thread-safe automatic disconnection of the callback
243  * if the callback represents or calls into a non-static method of an
244  * object which may be destroyed before the callback executes in the
245  * main loop, include a Releaser as a public member of that object and
246  * pass the Releaser object as the second argument of
247  * Callback::post(). Note that for this to be race free, the lifetime
248  * of the remote object whose method is to be invoked must be
249  * determined by the thread to whose main loop the callback has been
250  * attached. When the main loop begins invoking the execution of the
251  * callback, the remote object must either wholly exist (in which case
252  * the callback will be invoked) or have been destroyed (in which case
253  * the callback will be ignored), and not be in some transient
254  * half-state governed by another thread.
255  *
256  * Advantages as against Notifier:
257  *
258  * 1. If there are a lot of different events requiring callbacks to be
259  * dispatched in the program from worker threads to the main
260  * thread, this avoids having separate Notifier objects for each
261  * event.
262  * 2. It is easier to pass arguments with varying values - they can be
263  * passed as bound arguments of the callback and no special
264  * synchronisation is normally required (the call to
265  * g_source_attach() invokes locking of the main loop which will
266  * have the effect of ensuring memory visibility). With a Notifier
267  * object it may be necessary to use an asynchronous queue to pass
268  * variable values (or to bind a reference to the data, thus
269  * normally requiring separate synchronisation).
270  * 3. Although the callback would normally be sent for execution by
271  * the main program loop, and that is the default, it can be sent
272  * for execution by any thread which has its own
273  * GMainContext/GMainLoop objects. Thus callbacks can be passed
274  * for execution between worker threads, or from the main program
275  * thread to worker threads, as well as from worker threads to the
276  * main program thread.
277  *
278  * Disadvantages as against Notifier:
279  *
280  * 1. Less efficient, as a new callback object has to be created on
281  * freestore every time the callback is invoked, together with a
282  * new SafeEmitter object if a Releaser is used to track the
283  * callback.
284  * 2. Multiple callbacks relevant to a single event cannot be invoked
285  * from a single call for the event - each callback has to be
286  * separately dispatched.
287  */
288 
289 /**
290  * @namespace Cgu::Callback
291  * @brief This namespace provides classes for type erasure.
292  *
293  * \#include <c++-gtk-utils/callback.h>
294  *
295  * These classes provide type erasure on callable objects. They
296  * comprise a generic callback creation and execution interface for
297  * closures. There is a basic Callback::Callback type, which is an
298  * entire closure or 'thunk', where all values are bound into the
299  * object, and is completely opaque. Callback::CallbackArg<T...> is a
300  * class which takes unbound arguments of the template types when the
301  * object is dispatched. (The opaque Callback::Callback type is a
302  * typedef for Callback::CallbackArg<>: the two types are
303  * interchangeable.)
304  *
305  * Objects of these classes are normally constructed using the
306  * Callback::lambda() factory function, which takes any callable
307  * object such as a lambda expression or the return value of
308  * std::bind, and returns a pointer to a Callback/CallbackArg object
309  * allocated on free store. When using Callback::lambda(), the
310  * unbound argument types (if any) must be passed as explicit template
311  * parameters.
312  *
313  * Callback/CallbackArg objects can also be constructed using the
314  * Callback::make() and Callback::make_ref() factory functions, which
315  * can be useful where invoking standalone functions or object
316  * methods.
317  *
318  * From version 2.2.6, a convenience Callback::to_unique() function is
319  * available which will construct a std::unique_ptr object from a
320  * Callback/CallbackArg object returned by Callback::lambda(),
321  * Callback::make() or Callback::make_ref(), for the purpose of taking
322  * ownership of the Callback/CallbackArg object. This function is
323  * mainly intended for use with the auto keyword, to avoid having to
324  * write out the type of the unique_ptr object in longhand.
325  * Corresponding Callback::to_functor() and
326  * Callback::to_safe_functor() functions are also provided.
327  *
328  * The Callback/CallbackArg classes do not provide for a return
329  * value. If a result is wanted, users should pass an unbound argument
330  * by reference or pointer (or pointer to pointer).
331  *
332  * The Callback::make() and Callback::make_ref() functions
333  * -------------------------------------------------------
334  *
335  * The Callback::make() and Callback::make_ref() functions construct a
336  * Callback/CallbackArg object from a function pointer (or an object
337  * reference and member function pointer) together with bound
338  * arguments. They provide for a maximum of five bound arguments, and
339  * the unbound arguments (if any) must be the last (trailing)
340  * arguments of the relevant function or method to be called. From
341  * version 2.2.10, if a suitable compiler is used (gcc >= 4.8 or clang
342  * >= 3.4), up to ten bound arguments are permitted - see further
343  * below.
344  *
345  * Callback::make() does a direct type mapping from the bound
346  * arguments of the function or method represented by the callback
347  * object to the arguments stored by it and is for use when all bound
348  * arguments are simple fundamental types such as pointers (including
349  * C strings), integers or floating points.
350  *
351  * Callback::make_ref() is for use where bound arguments include class
352  * types or one or more of the types of the bound arguments include a
353  * const reference. It will accomplish perfect forwarding (by lvalue
354  * reference or rvalue reference) when constructing the callback and
355  * will also ensure that a copy of any object to be passed by const
356  * reference (as well as any taken by value) is kept in order to avoid
357  * dangling references. Note however that where a member function is
358  * called, the object of which the target function is a member must
359  * still be in existence when the Callback/CallbackArg object is
360  * dispatched and, unlike Callback::make(), Callback::make_ref()
361  * cannot be used with overloaded functions except with explicit
362  * disambiguation.
363  *
364  * Callback::make() can also construct a Callback/CallbackArg object
365  * from a std::function object.
366  *
367  * As mentioned above, from version 2.2.10 if a suitable compiler is
368  * used (gcc >= 4.8 or clang >= 3.4), up to ten bound arguments are
369  * permitted instead of the previous maximum of five, by using a
370  * std::tuple backend for relevant callback classes. The tuple
371  * backend can be explicitly disabled with the \--without-tuple
372  * configuration option (and it is implicitly disabled with gcc-4.6
373  * and gcc-4.7), in which case the former backend employing the
374  * implementation used prior to version 2.2.10 is retained. For
375  * compilers other than gcc and clang which adequately support
376  * std::tuple, the tuple backend can be manually selected with the
377  * \--with-tuple configuration option in place of the former backend.
378  * Both backends are ABI compatible, because for closure/callback
379  * implementation this library only exports the CallbackArg pure
380  * virtual class.
381  *
382  * Callback::FunctorArg and Callback::SafeFunctorArg classes
383  * ---------------------------------------------------------
384  *
385  * Functor/FunctorArg objects hold a Callback/CallbackArg object by
386  * SharedPtr to enable them to be shared by reference counting, and
387  * SafeFunctor/SafeFunctorArg objects hold them by SharedLockPtr,
388  * which have a thread safe reference count so that they may be shared
389  * between different threads. These classes also have an operator()()
390  * method so as to be callable with function syntax.
391  *
392  * Memory allocation
393  * -----------------
394  *
395  * If the library is installed using the
396  * \--with-glib-memory-slices-no-compat configuration option, any
397  * Callback/CallbackArg object will be constructed in glib memory
398  * slices rather than in the generic C++ free store.
399  *
400  * Usage
401  * -----
402  *
403  * Using Callback::lambda():
404  *
405  * @code
406  * using namespace Cgu;
407  *
408  * // here cb1 is of type Callback::Callback*
409  * auto cb1 = Callback::lambda<>([]() {std::cout << "Hello world\n";});
410  * cb1->dispatch();
411  * delete cb1;
412  *
413  * // here Callback::to_unique() is used to make a std::unique_ptr object to
414  * // manage the callback. cb2 is of type std::unique_ptr<const Callback::Callback>
415  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {std::cout << "Hello world\n";}));
416  * cb2->dispatch();
417  *
418  * // the same using Callback::Functor
419  * Callback::Functor f1{Callback::lambda<>([]() {std::cout << "Hello world\n";})};
420  * f1();
421  *
422  * int k = 5;
423  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, int&>>
424  * auto cb3 = Callback::to_unique(Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;}));
425  * int res;
426  * cb3->dispatch(2, res);
427  * std::cout << k << " times 10 times 2 is " << res << '\n';
428  *
429  * // the same using Callback::FunctorArg
430  * Callback::FunctorArg<int, int&> f2{Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;})};
431  * f2(2, res);
432  * std::cout << k << " times 10 times 2 is " << res << '\n';
433  * @endcode
434  *
435  * Using Callback::make(), with a class object my_obj of type MyClass,
436  * with a method void MyClass::my_method(int, int, const char*):
437  *
438  * @code
439  * using namespace Cgu;
440  *
441  * int arg1 = 1, arg2 = 5;
442  *
443  * // here cb1 is of type Callback::Callback*
444  * auto cb1 = Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n");
445  * cb1->dispatch();
446  * delete cb1;
447  *
448  * // here cb2 is of type std::unique_ptr<const Callback::Callback>
449  * auto cb2 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n"));
450  * cb2->dispatch();
451  *
452  * // the same using Callback::Functor
453  * Callback::Functor f1{Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n")};
454  * f1();
455  *
456  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, const char*>>
457  * auto cb3 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1));
458  * cb3->dispatch(arg2, "Hello\n");
459  *
460  * // the same using Callback::FunctorArg
461  * Callback::FunctorArg<int, const char*> f2{Callback::make(my_obj, &MyClass::my_method, arg1)};
462  * f2(arg2, "Hello\n");
463  * @endcode
464  *
465  * Using Callback::make_ref(), with a class object my_obj of type
466  * MyClass, with a method void MyClass::my_method(int, const
467  * Something&):
468  *
469  * @code
470  * int arg1 = 1;
471  * Something arg2;
472  * // here cb is of type std::unique_ptr<const Callback::Callback>
473  * auto cb = Callback::to_unique(Callback::make_ref(my_obj, &MyClass::my_method, arg1, arg2));
474  * @endcode
475  *
476  * Posting of callbacks
477  * --------------------
478  *
479  * This namespace also provides a Callback::post() function which will
480  * execute a callback in a glib main loop and can be used (amongst
481  * other things) to pass an event from a worker thread to the main
482  * program thread. In that respect, it provides an alternative to the
483  * Notifier class. It is passed either a pointer to a
484  * Callback::Callback object created with a call to Callback::lambda()
485  * (or Callback::make() or Callback::make_ref()), or it can be passed
486  * a callable object and the implementation will call
487  * Callback::lambda() for you.
488  *
489  * To provide for thread-safe automatic disconnection of the callback
490  * if the callback represents or calls into a non-static method of an
491  * object which may be destroyed before the callback executes in the
492  * main loop, include a Releaser as a public member of that object and
493  * pass the Releaser object as the second argument of
494  * Callback::post(). Note that for this to be race free, the lifetime
495  * of the remote object whose method is to be invoked must be
496  * determined by the thread to whose main loop the callback has been
497  * attached. When the main loop begins invoking the execution of the
498  * callback, the remote object must either wholly exist (in which case
499  * the callback will be invoked) or have been destroyed (in which case
500  * the callback will be ignored), and not be in some transient
501  * half-state governed by another thread.
502  *
503  * Advantages as against Notifier:
504  *
505  * 1. If there are a lot of different events requiring callbacks to be
506  * dispatched in the program from worker threads to the main
507  * thread, this avoids having separate Notifier objects for each
508  * event.
509  * 2. It is easier to pass arguments with varying values - they can be
510  * passed as bound arguments of the callback and no special
511  * synchronisation is normally required (the call to
512  * g_source_attach() invokes locking of the main loop which will
513  * have the effect of ensuring memory visibility). With a Notifier
514  * object it may be necessary to use an asynchronous queue to pass
515  * variable values (or to bind a reference to the data, thus
516  * normally requiring separate synchronisation).
517  * 3. Although the callback would normally be sent for execution by
518  * the main program loop, and that is the default, it can be sent
519  * for execution by any thread which has its own
520  * GMainContext/GMainLoop objects. Thus callbacks can be passed
521  * for execution between worker threads, or from the main program
522  * thread to worker threads, as well as from worker threads to the
523  * main program thread.
524  *
525  * Disadvantages as against Notifier:
526  *
527  * 1. Less efficient, as a new callback object has to be created on
528  * freestore every time the callback is invoked, together with a
529  * new SafeEmitter object if a Releaser is used to track the
530  * callback.
531  * 2. Multiple callbacks relevant to a single event cannot be invoked
532  * from a single call for the event - each callback has to be
533  * separately dispatched.
534  */
535 
536 #include <functional> // for std::less, std::function and std::hash<T*>
537 #include <utility> // for std::move and std::forward
538 #include <memory> // for std::unique_ptr
539 #include <cstddef> // for std::size_t
540 #include <type_traits> // for std::remove_reference, std::remove_const and std::enable_if
541 
542 #include <glib.h>
543 
545 #include <c++-gtk-utils/param.h>
547 
548 #ifdef CGU_USE_TUPLE
549 #include <tuple>
550 #endif
551 
552 
553 namespace Cgu {
554 
555 namespace Callback {
556 
557 /*
558  The CallbackArg class could be additionally templated to provide a
559  return value, but that would affect the simplicity of the
560  interface, and if a case were to arise where a result is needed, an
561  alternative is for users to pass an argument by reference or
562  pointer (or pointer to pointer) rather than have a return value.
563 */
564 
565 /* Declare the two interface types */
566 
567 template <class... FreeArgs> class CallbackArg;
568 typedef CallbackArg<> Callback;
569 
570 /* now the class definitions */
571 
572 /**
573  * @class CallbackArg callback.h c++-gtk-utils/callback.h
574  * @brief The callback interface class
575  * @sa Callback namespace
576  * @sa FunctorArg SafeFunctorArg
577  *
578  * This class provides type erasure for callable objects. The
579  * CallbackArg type is constructed on free store and can wrap any
580  * callable object, such as a lambda expression or the return value of
581  * std::bind.
582  *
583  * The class is particularly relevant where a callable object with
584  * bound values needs to be handed safely between threads, or in other
585  * cases where a callback object has to be passed by pointer (which
586  * will happen at some stage with glib or pthreads). They are
587  * therefore useful for general event passing when used together with
588  * the Callback::post() functions or as the continuation for GIO async
589  * operations, and are more efficient than constructing std::function
590  * objects on free store and passing them by pointer (they avoid one
591  * level of indirection and only require one rather than two
592  * allocations).
593  *
594  * The classes are also used in the Emitter/EmitterArg and
595  * SafeEmitter/SafeEmitterArg classes in emitter.h, which enable
596  * callable objects to be connected to an emitter and provide for
597  * automatic disconnection where a class object whose member a
598  * callback represents or calls into ceases to exist. They are also
599  * used internally to implement the Thread::Future and
600  * Thread::TaskManager classes.
601  *
602  * The template types are the types of the unbound arguments, if any.
603  * Callback::CallbackArg<> is typedef'ed to Callback::Callback. The
604  * main method of constructing a Callback/CallbackArg object is with
605  * the Callback::lambda() factory function. When using
606  * Callback::lambda(), the unbound argument types (if any) must be
607  * passed as explicit template parameters.
608  *
609  * Callback/CallbackArg classes do not provide for a return value. If
610  * a result is wanted, users should pass an unbound argument by
611  * reference or pointer (or pointer to pointer).
612  *
613  * The 2.2 series of the library generally dispenses with the need to
614  * create objects explicitly using Callback::lambda() when calling
615  * into the library itself: all the library interfaces which take a
616  * Callback/CallbackArg object also now provide an overload which
617  * takes any callable object as a template type, and the
618  * implementation calls Callback::lambda() internally for you.
619  *
620  * @b Usage
621  *
622  * These are examples:
623  *
624  * @code
625  * using namespace Cgu;
626  *
627  * // here cb1 is of type Callback::Callback*
628  * auto cb1 = Callback::lambda<>([]() {std::cout << "Hello world\n";});
629  * cb1->dispatch();
630  * delete cb1;
631  *
632  * // here Callback::to_unique() is used to make a std::unique_ptr object to
633  * // manage the callback. cb2 is of type std::unique_ptr<const Callback::Callback>
634  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {std::cout << "Hello world\n";}));
635  * cb2->dispatch();
636  *
637  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, int&>>
638  * auto cb3 = Callback::to_unique(Callback::lambda<int, int&>([] (int i, int& j) {j = 10 * i;}));
639  * int res;
640  * cb3->dispatch(2, res);
641  * std::cout << "10 times 2 is " << res << '\n';
642  * @endcode
643  *
644  * For further background, including about the Callback::make(),
645  * Callback::make_ref() and Callback::to_unique() functions, read
646  * this: Callback
647  */
648 
649 template <class... FreeArgs>
650 class CallbackArg {
651 public:
652 /* Because dispatch() is a virtual function, we cannot templatise it
653  * with a view to preserving r-value forwarding of temporary objects
654  * passed as a free argument. But this would rarely be relevant
655  * anyway - it would only be relevant if the target function were to
656  * take an argument by r-value reference and a temporary were to be
657  * passed to it. In such a case virtual dispatch is at the cost of a
658  * copy of the temporary.
659  */
660 /**
661  * This will execute the referenced function, callable object or class
662  * method encapsulated by this class. It will only throw if the
663  * dispatched function, callable object or class method throws, or if
664  * the copy constructor of a free or bound argument throws and it is
665  * not a reference argument. It is thread safe if the referenced
666  * function or class method is thread safe.
667  * @param args The unbound arguments to be passed to the referenced
668  * function, callable object or class method, if any.
669  * @note We use dispatch() to execute the callback, because the
670  * callback would normally be invoked through a base class pointer.
671  * To invoke it through operator()(), use the FunctorArg or
672  * SafeFunctorArg wrapper class.
673  */
674  virtual void dispatch(typename Cgu::Param<FreeArgs>::ParamType... args) const = 0;
675 
676 /**
677  * The constructor will not throw unless the copy constructor of an
678  * argument bound to the derived implementation class throws.
679  */
681 
682 /**
683  * The destructor will not throw unless the destructor of an argument
684  * bound to the derived implementation class throws.
685  */
686  virtual ~CallbackArg() {}
687 
688 /* these functions will be inherited by the derived callback classes */
689 #ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT
691 #endif
692 };
693 
694 /**
695  * A function for making a std::unique_ptr object from a
696  * Cgu::Callback::CallbackArg object (say, as constructed by
697  * Cgu::Callback::lambda(), Cgu::Callback::make() or
698  * Cgu::Callback::make_ref()), for the purpose of taking ownership of
699  * the CallbackArg object. It is thread safe and will not throw.
700  *
701  * This function is mainly intended for use with the auto keyword, to
702  * avoid having to write out the type of the unique_ptr object in
703  * longhand. For example:
704  *
705  * @code
706  * using namespace Cgu;
707  * // here a std::unique_ptr<const Cgu::Callback::CallbackArg<const std::string&>> object is constructed
708  * auto cb = Callback::to_unique(Callback::lambda<const std::string&>([] (const std::string& s) {
709  * std::cout << s;
710  * }));
711  * cb->dispatch("Hello\n");
712  * @endcode
713  *
714  * This function cannot be used to overcome the problems of C++'s
715  * unconstrained partial evaluation rules for functions taking more
716  * than one argument (the lack of such constraints is a poor design
717  * choice for a language with exceptions such as C++, and is due to
718  * change with C++17 - see further below). For example, at present a
719  * function:
720  *
721  * @code
722  * void do_it(std::unique_ptr<const Cgu::Callback::Callback> cb1,
723  * std::unique_ptr<const Cgu::Callback::Callback> cb2);
724  * @endcode
725  * should not be called like this:
726  * @code
727  * do_it(Callback::to_unique(Callback::lambda<>([]() {...;})),
728  * Callback::to_unique(Callback::lambda<>([]() {...;})));
729  * @endcode
730  *
731  * This is because one possible sequencing that C++14 and earlier
732  * permit is as follows:
733  *
734  * 1. Construct the callback object for the first argument by calling
735  * Callback::lambda().
736  * 2. Construct the callback object for the second argument by calling
737  * Callback::lambda().
738  * 3. Initialize a std::unique_ptr object for the second argument by
739  * calling Callback::to_unique().
740  * 4. Initialize a std::unique_ptr object for the first argument by
741  * calling Callback::to_unique().
742  * 5. Enter do_it().
743  *
744  * Because step 2 is permitted to precede step 4, if step 2 throws
745  * then the object constructed at step 1 will be leaked. To avoid
746  * this, explicit sequencing must be provided for in the code, as
747  * follows:
748  *
749  * @code
750  * auto cb1 = Callback::to_unique(Callback::lambda<>([]() {...;}));
751  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {...;}));
752  * do_it(std::move(cb1),
753  * std::move(cb2));
754  * @endcode
755  *
756  * The current proposals for C++17 preventing interleaving when
757  * evaluating function arguments (P0145R1) means that, if adopted in
758  * C++17 as seems likely, these issues should not affect code compiled
759  * with a C++17 compiler option.
760  *
761  * The Cgu::Callback::CallbackArg object held by the unique_ptr
762  * returned by this function is const. This is because all the
763  * interfaces in this library also take const
764  * Cgu::Callback::CallbackArg objects (and their only method, the
765  * dispatch() method, is const). However, if constructed using
766  * Cgu::Callback::lambda(), Cgu::Callback::make() or
767  * Cgu::Callback::make_ref(), the Cgu::Callback::CallbackArg object
768  * can safely be cast to non-const.
769  *
770  * @param cb The CallbackArg object which is to be managed by a
771  * std::unique_ptr.
772  * @return The std::unique_ptr object.
773  *
774  * Since 2.0.23 and 2.2.6
775  */
776 template<class... T>
777 std::unique_ptr<const CallbackArg<T...>> to_unique(const CallbackArg<T...>* cb) noexcept {
778  return std::unique_ptr<const CallbackArg<T...>>(cb);
779 }
780 
781 /* The four basic functor types */
782 
783 template <class... FreeArgs> class FunctorArg;
784 template <class... FreeArgs> class SafeFunctorArg;
785 typedef FunctorArg<> Functor;
787 
788 /* Functor friend functions */
789 
790 // we can use built-in operator == when comparing pointers referencing
791 // different objects of the same type
792 /**
793  * Two FunctorArg objects compare equal if the addresses of the
794  * CallbackArg objects they contain are the same. This comparison
795  * operator does not throw.
796  */
797 template <class... T>
798 bool operator==(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) noexcept {
799  return (f1.cb_s.get() == f2.cb_s.get());
800 }
801 
802 /**
803  * Two FunctorArg objects compare unequal if the addresses of the
804  * CallbackArg objects they contain are not the same. This comparison
805  * operator does not throw.
806  */
807 template <class... T>
808 bool operator!=(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) noexcept {
809  return !(f1 == f2);
810 }
811 
812 // we must use std::less rather than the < built-in operator for
813 // pointers to objects not within the same array or object: "For
814 // templates greater, less, greater_equal, and less_equal, the
815 // specializations for any pointer type yield a total order, even if
816 // the built-in operators <, >, <=, >= do not." (para 20.3.3/8).
817 /**
818  * One FunctorArg object is less than another if the address of the
819  * CallbackArg object contained by the first is regarded by std::less
820  * as less than the address of the CallbackArg object contained by the
821  * other. This comparison operator does not throw unless std::less
822  * applied to pointer types throws (which it would not do with any
823  * sane implementation).
824  */
825 template <class... T>
826 bool operator<(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) {
827  return std::less<const CallbackArg<T...>*>()(f1.cb_s.get(), f2.cb_s.get());
828 }
829 
830 /**
831  * Two SafeFunctorArg objects compare equal if the addresses of the
832  * CallbackArg objects they contain are the same. This comparison
833  * operator does not throw.
834  */
835 template <class... T>
836 bool operator==(const SafeFunctorArg<T...>& f1, const SafeFunctorArg<T...>& f2) noexcept {
837  return (f1.cb_s.get() == f2.cb_s.get());
838 }
839 
840 /**
841  * Two SafeFunctorArg objects compare unequal if the addresses of the
842  * CallbackArg objects they contain are not the same. This comparison
843  * operator does not throw.
844  */
845 template <class... T>
846 bool operator!=(const SafeFunctorArg<T...>& f1, const SafeFunctorArg<T...>& f2) noexcept {
847  return !(f1 == f2);
848 }
849 
850 /**
851  * One SafeFunctorArg object is less than another if the address of
852  * the CallbackArg object contained by the first is regarded by
853  * std::less as less than the address of the CallbackArg object
854  * contained by the other. This comparison operator does not throw
855  * unless std::less applied to pointer types throws (which it would
856  * not do with any sane implementation).
857  */
858 template <class... T>
860  return std::less<const CallbackArg<T...>*>()(f1.cb_s.get(), f2.cb_s.get());
861 }
862 
863 } // namespace Callback
864 } // namespace Cgu
865 
866 // doxygen produces long filenames that tar can't handle:
867 // we have generic documentation for std::hash specialisations
868 // in doxygen.main.in
869 #ifndef DOXYGEN_PARSING
870 
871 /* These structs allow FunctorArg and SafeFunctorArg objects to be
872  keys in unordered associative containers */
873 namespace std {
874 template <class... T>
875 struct hash<Cgu::Callback::FunctorArg<T...>> {
876  typedef std::size_t result_type;
877  typedef Cgu::Callback::FunctorArg<T...> argument_type;
878  result_type operator()(const argument_type& f) const {
879  // this is fine: std::hash structs do not normally contain data and
880  // std::hash<T*> certainly won't, so we don't have overhead constructing
881  // std::hash<T*> on the fly
882  return std::hash<const Cgu::Callback::CallbackArg<T...>*>()(f.cb_s.get());
883  }
884 };
885 template <class... T>
886 struct hash<Cgu::Callback::SafeFunctorArg<T...>> {
887  typedef std::size_t result_type;
888  typedef Cgu::Callback::SafeFunctorArg<T...> argument_type;
889  result_type operator()(const argument_type& f) const {
890  // this is fine: std::hash structs do not normally contain data and
891  // std::hash<T*> certainly won't, so we don't have overhead constructing
892  // std::hash<T*> on the fly
893  return std::hash<const Cgu::Callback::CallbackArg<T...>*>()(f.cb_s.get());
894  }
895 };
896 } // namespace std
897 
898 #endif // DOXYGEN_PARSING
899 
900 namespace Cgu {
901 namespace Callback {
902 
903 /* the functor classes */
904 
905 /**
906  * @class FunctorArg callback.h c++-gtk-utils/callback.h
907  * @brief Functor class holding a Callback::CallbackArg object.
908  * @sa SafeFunctorArg
909  * @sa Callback namespace
910  *
911  * This class wraps a CallbackArg object. The callback object is kept
912  * by SharedPtr so the functor can be copied and offers automatic
913  * lifetime management of the wrapped callback object, as well as
914  * providing an operator()() function. Ownership is taken of the
915  * CallbackArg object passed to the constructor taking a CallbackArg
916  * pointer, so that constructor should be treated like a shared
917  * pointer constructor - only pass a newly allocated object to it (or
918  * copy construct it or assign to it from another existing FunctorArg
919  * object). The template types are the types of the unbound
920  * arguments, if any. Callback::FunctorArg<> is typedef'ed to
921  * Callback::Functor.
922  *
923  * The constructor taking a Callback::CallbackArg pointer is not
924  * marked explicit, so the results of Callback::lambda(),
925  * Callback::make() or Callback::make_ref() can be passed directly to
926  * a function taking a Callback::FunctorArg argument, and implicit
927  * conversion will take place.
928  *
929  * Functor/FunctorArg classes do not provide for a return value. If
930  * a result is wanted, users should pass an unbound argument by
931  * reference or pointer (or pointer to pointer).
932  *
933  * @b Usage
934  *
935  * These are examples:
936  *
937  * @code
938  * using namespace Cgu;
939  *
940  * // here f1 is directly initialized using the type conversion constructor
941  * Callback::Functor f1{Callback::lambda<>([] () {std::cout << "Hello world\n";})};
942  * f1();
943  *
944  * // here Callback::to_functor() is used to enable use of the auto keyword.
945  * // f2 is of type Callback::Functor
946  * auto f2 = Callback::to_functor(Callback::lambda<>([] () {std::cout << "Hello world\n";}));
947  * f2();
948  *
949  * // here f3 is of type Callback::FunctorArg<int, int&>
950  * auto f3 = Callback::to_functor(Callback::lambda<int, int&>([] (int i, int& j) {j = 10 * i;}));
951  * int res;
952  * f3(2, res);
953  * std::cout << "10 times 2 is " << res << '\n';
954  * @endcode
955  *
956  * For further background, including about the Callback::make(),
957  * Callback::make_ref() and Callback::to_functor() functions, read
958  * this: Callback
959  */
960 
961 template <class... FreeArgs>
962 class FunctorArg {
963  SharedPtr<const CallbackArg<FreeArgs...>> cb_s;
964 public:
965 /* Because CallbackArg::dispatch() is a virtual function, it is
966  * pointless templatising this function with a view to preserving
967  * r-value forwarding of temporary objects passed as a free argument,
968  * because the r-value typeness will be discarded in dispatch(). But
969  * this would rarely be relevant anyway - it would only be relevant if
970  * the target function were to take an argument by r-value reference
971  * and a temporary were to be passed to it. In such a case virtual
972  * dispatch is at the cost of a copy of the temporary.
973  */
974 /**
975  * This will execute the function, callable object or class method
976  * represented by the callback encapsulated by this object, or do
977  * nothing if this object has not been initialized with a callback.
978  * It will only throw if the executed function, callable object or
979  * class method throws, or if the copy constructor of a free or bound
980  * argument throws and it is not a reference argument. It is thread
981  * safe if the referenced function or class method is thread safe.
982  * @param args The unbound arguments to be passed to the referenced
983  * function, callable object or class method, if any.
984  */
985  void operator()(typename Cgu::Param<FreeArgs>::ParamType... args) const {
986  if (cb_s.get()) cb_s->dispatch(args...);
987  }
988 
989 /**
990  * This function does not throw.
991  * @param f The assignor.
992  * @return The functor object after assignment.
993  */
994  FunctorArg& operator=(const FunctorArg& f) {cb_s = f.cb_s; return *this;}
995 
996 /**
997  * This function does not throw.
998  * @param f The functor to be moved.
999  * @return The functor object after the move operation.
1000  */
1001  FunctorArg& operator=(FunctorArg&& f) {cb_s = std::move(f.cb_s); return *this;}
1002 
1003 /**
1004  * Two FunctorArg objects compare equal if the addresses of the
1005  * CallbackArg objects they contain are the same. This comparison
1006  * operator does not throw.
1007  */
1008  friend bool operator== <>(const FunctorArg&, const FunctorArg&) noexcept;
1009 
1010 /**
1011  * One FunctorArg object is less than another if the address of the
1012  * CallbackArg object contained by the first is regarded by std::less
1013  * as less than the address of the CallbackArg object contained by the
1014  * other. This comparison operator does not throw unless std::less
1015  * applied to pointer types throws (which it would not do with any
1016  * sane implementation).
1017  */
1018  friend bool operator< <>(const FunctorArg&, const FunctorArg&);
1019 
1020  friend struct std::hash<FunctorArg>;
1021 
1022 /**
1023  * Constructor of first FunctorArg holding the referenced callback.
1024  * As it is not marked explicit, it is also a type conversion
1025  * constructor.
1026  * @param cb The CallbackArg object which the functor is to manage.
1027  * @exception std::bad_alloc This might throw std::bad_alloc if
1028  * memory is exhausted and the system throws in that case. Note that
1029  * if such an exception is thrown, then this constructor will clean
1030  * itself up and also delete the callback object passed to it.
1031  * @note std::bad_alloc will not be thrown if the library has been
1032  * installed using the \--with-glib-memory-slices-no-compat
1033  * configuration option: instead glib will terminate the program if it
1034  * is unable to obtain memory from the operating system.
1035  */
1036  FunctorArg(const CallbackArg<FreeArgs...>* cb): cb_s(cb) {}
1037 
1038 /**
1039  * The copy constructor does not throw.
1040  * @param f The assignor
1041  */
1042  FunctorArg(const FunctorArg& f): cb_s(f.cb_s) {}
1043 
1044 /**
1045  * The move constructor does not throw.
1046  * @param f The functor to be moved.
1047  */
1048  FunctorArg(FunctorArg&& f): cb_s(std::move(f.cb_s)) {}
1049 
1050  /**
1051  * Default constructor, where a Callback::CallbackArg object is to be
1052  * assigned later (via the type conversion constructor and/or the
1053  * assignment operator). This constructor does not throw.
1054  */
1056 
1057 /* Only has effect if --with-glib-memory-slices-compat or
1058  --with-glib-memory-slices-no-compat option picked */
1060 };
1061 
1062 /**
1063  * @class SafeFunctorArg callback.h c++-gtk-utils/callback.h
1064  * @brief Functor class holding a Callback::CallbackArg object, with
1065  * thread-safe reference count.
1066  * @sa FunctorArg
1067  * @sa Callback namespace
1068  *
1069  * This class wraps a CallbackArg object. It is the same as
1070  * Callback::FunctorArg except that it will provide synchronisation of
1071  * the reference count between threads. Use it where a functor
1072  * wrapper object is to be passed between threads. The FunctorArg
1073  * documentation gives further details. The
1074  * Callback::to_safe_functor() function can be used in place of the
1075  * Callback::to_functor() function when constructing a
1076  * Callback::SafeFunctorArg object using the auto keyword.
1077  *
1078  * Callback::SafeFunctorArg<> is typedef'ed to Callback::SafeFunctor.
1079  *
1080  * For further background, including about the Callback::make(),
1081  * Callback::make_ref() and Callback::to_safe_functor() functions,
1082  * read this: Callback
1083  */
1084 
1085 template <class... FreeArgs>
1086 class SafeFunctorArg {
1087  SharedLockPtr<const CallbackArg<FreeArgs...>> cb_s;
1088 public:
1089 /**
1090  * This will execute the function, callable object or class method
1091  * represented by the callback encapsulated by this object, or do
1092  * nothing if this object has not been initialized with a callback.
1093  * It will only throw if the executed function, callable object or
1094  * class method throws, or if the copy constructor of a free or bound
1095  * argument throws and it is not a reference argument. It is thread
1096  * safe if the referenced function or class method is thread safe.
1097  * @param args The unbound arguments to be passed to the referenced
1098  * function, callable object or class method, if any.
1099  */
1100  void operator()(typename Cgu::Param<FreeArgs>::ParamType... args) const {
1101  if (cb_s.get()) cb_s->dispatch(args...);
1102  }
1103 
1104 /**
1105  * This function does not throw.
1106  * @param f The assignor.
1107  * @return The functor object after assignment.
1108  */
1109  SafeFunctorArg& operator=(const SafeFunctorArg& f) {cb_s = f.cb_s; return *this;}
1110 
1111 /**
1112  * This function does not throw.
1113  * @param f The functor to be moved.
1114  * @return The functor object after the move operation.
1115  */
1116  SafeFunctorArg& operator=(SafeFunctorArg&& f) {cb_s = std::move(f.cb_s); return *this;}
1117 
1118 /**
1119  * Two SafeFunctorArg objects compare equal if the addresses of the
1120  * CallbackArg objects they contain are the same. This comparison
1121  * operator does not throw.
1122  */
1123  friend bool operator== <>(const SafeFunctorArg&, const SafeFunctorArg&) noexcept;
1124 
1125 /**
1126  * One SafeFunctorArg object is less than another if the address of
1127  * the CallbackArg object contained by the first is regarded by
1128  * std::less as less than the address of the CallbackArg object
1129  * contained by the other. This comparison operator does not throw
1130  * unless std::less applied to pointer types throws (which it would
1131  * not do with any sane implementation).
1132  */
1133  friend bool operator< <>(const SafeFunctorArg&, const SafeFunctorArg&);
1134 
1135  friend struct std::hash<SafeFunctorArg>;
1136 
1137  /**
1138  * Constructor of first SafeFunctorArg holding the referenced
1139  * callback. As it is not marked explicit, it is also a type
1140  * conversion constructor.
1141  * @param cb The CallbackArg object which the functor is to manage.
1142  * @exception std::bad_alloc This might throw std::bad_alloc if
1143  * memory is exhausted and the system throws in that case. Note that
1144  * if such an exception is thrown, then this constructor will clean
1145  * itself up and also delete the callback object passed to it.
1146  * @note std::bad_alloc will not be thrown if the library has been
1147  * installed using the \--with-glib-memory-slices-no-compat
1148  * configuration option: instead glib will terminate the program if it
1149  * is unable to obtain memory from the operating system.
1150  */
1151  SafeFunctorArg(const CallbackArg<FreeArgs...>* cb): cb_s(cb) {}
1152 
1153 /**
1154  * The copy constructor does not throw.
1155  * @param f The assignor.
1156  */
1157  SafeFunctorArg(const SafeFunctorArg& f): cb_s(f.cb_s) {}
1158 
1159 /**
1160  * The move constructor does not throw.
1161  * @param f The functor to be moved.
1162  */
1163  SafeFunctorArg(SafeFunctorArg&& f): cb_s(std::move(f.cb_s)) {}
1164 
1165  /**
1166  * Default constructor, where a Callback::CallbackArg object is to be
1167  * assigned later (via the type conversion constructor and/or the
1168  * assignment operator). This constructor does not throw.
1169  * @note The reference count maintained with respect to the contained
1170  * callback object is thread-safe, so SafeFunctorArg objects may be
1171  * copied between threads by the implicit assignment operator and put
1172  * in different containers in different threads. They use a
1173  * SharedLockPtr object to hold the referenced callback object.
1174  */
1176 
1177 /* Only has effect if --with-glib-memory-slices-compat or
1178  --with-glib-memory-slices-no-compat option picked */
1180 };
1181 
1182 /**
1183  * A function for making a Cgu::Callback::FunctorArg object from a
1184  * Cgu::Callback::CallbackArg object, for the purpose of taking
1185  * ownership of the CallbackArg object. It is thread safe.
1186  *
1187  * Because the constructor of FunctorArg taking a pointer is not
1188  * explicit and can therefore be used for implicit type conversion,
1189  * this function will not often be needed. It is mainly intended for
1190  * use when constructing a named object in local scope with the auto
1191  * keyword, to avoid having to write out the type of the FunctorArg
1192  * object in longhand. For example:
1193  *
1194  * @code
1195  * using namespace Cgu;
1196  * // here a Cgu::Callback::FunctorArg<const std::string&> object is constructed
1197  * auto f = Callback::to_functor(Callback::lambda<const std::string&>([] (const std::string& s) {
1198  * std::cout << s;
1199  * }));
1200  * f("Hello\n");
1201  * @endcode
1202  *
1203  * @param cb The CallbackArg object which is to be managed by a
1204  * functor.
1205  * @return The FunctorArg object.
1206  * @exception std::bad_alloc This function might throw std::bad_alloc
1207  * if memory is exhausted and the system throws in that case. Note
1208  * that if such an exception is thrown, then this function will delete
1209  * the callback object passed to it.
1210  * @note std::bad_alloc will not be thrown if the library has been
1211  * installed using the \--with-glib-memory-slices-no-compat
1212  * configuration option: instead glib will terminate the program if it
1213  * is unable to obtain memory from the operating system.
1214  *
1215  * Since 2.0.23 and 2.2.6
1216  */
1217 template<class... T>
1219  return cb;
1220 }
1221 
1222 /**
1223  * A function for making a Cgu::Callback::SafeFunctorArg object from a
1224  * Cgu::Callback::CallbackArg object, for the purpose of taking
1225  * ownership of the CallbackArg object. It is thread safe.
1226  *
1227  * Because the constructor of SafeFunctorArg taking a pointer is not
1228  * explicit and can therefore be used for implicit type conversion,
1229  * this function will not often be needed. It is mainly intended for
1230  * use when constructing a named object in local scope with the auto
1231  * keyword, to avoid having to write out the type of the
1232  * SafeFunctorArg object in longhand. For example:
1233  *
1234  * @code
1235  * using namespace Cgu;
1236  * // here a Cgu::Callback::SafeFunctorArg<const std::string&> object is constructed
1237  * auto f = Callback::to_safe_functor(Callback::lambda<const std::string&>([] (const std::string& s) {
1238  * std::cout << s;
1239  * }));
1240  * f("Hello\n");
1241  * @endcode
1242  *
1243  * @param cb The CallbackArg object which is to be managed by a
1244  * functor.
1245  * @return The SafeFunctorArg object.
1246  * @exception std::bad_alloc This function might throw std::bad_alloc
1247  * if memory is exhausted and the system throws in that case. Note
1248  * that if such an exception is thrown, then this function will delete
1249  * the callback object passed to it.
1250  * @note std::bad_alloc will not be thrown if the library has been
1251  * installed using the \--with-glib-memory-slices-no-compat
1252  * configuration option: instead glib will terminate the program if it
1253  * is unable to obtain memory from the operating system.
1254  *
1255  * Since 2.0.23 and 2.2.6
1256  */
1257 template<class... T>
1259  return cb;
1260 }
1261 
1262 /* the callback implementation classes */
1263 
1264 // generic class for callable objects such as lambdas
1265 template <class Lambda, class... FreeArgs>
1266 class Callback_lambda: public CallbackArg<FreeArgs...> {
1267  // making 'l' mutable means that Callback_lamdba objects can contain
1268  // mutable lambda expressions
1269  mutable Lambda l;
1270 public:
1271  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {l(free_args...);}
1272  template <class L> Callback_lambda(L&& l_): l(std::forward<L>(l_)) {}
1273 };
1274 
1275 #if defined(DOXYGEN_PARSING) || defined(CGU_USE_TUPLE)
1276 
1277 // classes for function types
1278 template <class T, class MemFunc, class Tuple, class... FreeArgs>
1279 class Callback_memfun_tuple: public CallbackArg<FreeArgs...> {
1280  T* obj;
1281  MemFunc func;
1282  Tuple tuple;
1283 public:
1284  // see param.h for tuple_apply()
1285  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1286  tuple_apply(*obj, func, tuple, free_args...);
1287  }
1288  template <class... Args>
1289  Callback_memfun_tuple(T& obj_, MemFunc func_, Args&&... args):
1290  obj(&obj_), func(func_), tuple(std::forward<Args>(args)...) {}
1291 };
1292 
1293 // this non-tuple version for member function pointers with object but
1294 // no arguments is a minor space saving device: std::tuple<> will have
1295 // a sizeof of 1, which will normally expand the size of the aligned
1296 // callback class holding it by 4. This avoids that.
1297 template <class T, class MemFunc, class... FreeArgs>
1298 class Callback_memfun: public CallbackArg<FreeArgs...> {
1299  T* obj;
1300  MemFunc func;
1301 public:
1302  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1303  (obj->*func)(free_args...);
1304  }
1305  Callback_memfun(T& obj_, MemFunc func_): obj(&obj_), func(func_) {}
1306 };
1307 
1308 // we don't need a version of this not taking a tuple - we can use
1309 // Callback_lambda for function pointers with no bound arguments
1310 template <class Func, class Tuple, class... FreeArgs>
1311 class Callback_fun_tuple: public CallbackArg<FreeArgs...> {
1312  Func func;
1313  Tuple tuple;
1314 public:
1315  // see param.h for tuple_apply()
1316  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1317  tuple_apply(func, tuple, free_args...);
1318  }
1319  template <class... Args>
1320  Callback_fun_tuple(Func func_, Args&&... args):
1321  func(func_), tuple(std::forward<Args>(args)...) {}
1322 };
1323 
1324 /* Convenience functions making callback objects on freestore. These
1325  * can for example be passed as the first argument of the
1326  * Thread::start() method in thread.h. They are also used by the
1327  * Callback::post() function.
1328 */
1329 
1330 /**
1331  * A convenience function to make Callback::CallbackArg objects
1332  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1333  * is exhausted and the system throws in that case. This exception
1334  * will not be thrown if the library has been installed using the
1335  * \--with-glib-memory-slices-no-compat configuration option (instead
1336  * glib will terminate the program if it is unable to obtain memory
1337  * from the operating system).
1338  */
1339 template <class T, class... FreeArgs>
1340 CallbackArg<FreeArgs...>* make(T& t,
1341  void (T::*func)(FreeArgs...)) {
1342  return new Callback_memfun<T, decltype(func), FreeArgs...>{t, func};
1343 }
1344 
1345 /**
1346  * Since this function constructs a callback which does not take a
1347  * bound argument, it is a synonym for make() (the two are identical).
1348  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1349  * is exhausted and the system throws in that case. This exception
1350  * will not be thrown if the library has been installed using the
1351  * \--with-glib-memory-slices-no-compat configuration option (instead
1352  * glib will terminate the program if it is unable to obtain memory
1353  * from the operating system).
1354  *
1355  * Since 2.0.0-rc3
1356  */
1357 template <class T, class... FreeArgs>
1358 CallbackArg<FreeArgs...>* make_ref(T& t,
1359  void (T::*func)(FreeArgs...)) {
1360  return new Callback_memfun<T, decltype(func), FreeArgs...>{t, func};
1361 }
1362 
1363 /**
1364  * A convenience function to make Callback::CallbackArg objects
1365  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1366  * is exhausted and the system throws in that case (this exception
1367  * will not be thrown if the library has been installed using the
1368  * \--with-glib-memory-slices-no-compat configuration option: instead
1369  * glib will terminate the program if it is unable to obtain memory
1370  * from the operating system). It will also throw if the copy
1371  * constructor of a bound argument throws and it is not a reference
1372  * argument.
1373  */
1374 template <class T, class BoundArg, class... FreeArgs>
1375 CallbackArg<FreeArgs...>* make(T& t,
1376  void (T::*func)(BoundArg, FreeArgs...),
1377  BoundArg arg) {
1378  typedef std::tuple<BoundArg> Tuple;
1379  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1380  {t, func, arg};
1381 }
1382 
1383 /**
1384  * An alternative function to make Callback::CallbackArg objects,
1385  * which is for use where a target function either receives a class
1386  * type bound argument by value, or receives a bound argument by
1387  * reference to const in a case where the generated CallbackArg object
1388  * is to store a copy of that argument instead of just keeping a
1389  * reference.
1390  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1391  * is exhausted and the system throws in that case (this exception
1392  * will not be thrown if the library has been installed using the
1393  * \--with-glib-memory-slices-no-compat configuration option: instead
1394  * glib will terminate the program if it is unable to obtain memory
1395  * from the operating system). It will also throw if the copy or move
1396  * constructor of a bound argument throws.
1397  *
1398  * Since 2.0.0-rc3
1399  */
1400 template <class T, class BoundArg, class Arg, class... FreeArgs>
1401 CallbackArg<FreeArgs...>* make_ref(T& t,
1402  void (T::*func)(BoundArg, FreeArgs...),
1403  Arg&& arg) {
1404  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg>::type>::type> Tuple;
1405  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1406  {t, func, std::forward<Arg>(arg)};
1407 }
1408 
1409 /**
1410  * A convenience function to make Callback::CallbackArg objects
1411  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1412  * is exhausted and the system throws in that case (this exception
1413  * will not be thrown if the library has been installed using the
1414  * \--with-glib-memory-slices-no-compat configuration option: instead
1415  * glib will terminate the program if it is unable to obtain memory
1416  * from the operating system). It will also throw if the copy
1417  * constructor of a bound argument throws and it is not a reference
1418  * argument.
1419  */
1420 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1421 CallbackArg<FreeArgs...>* make(T& t,
1422  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1423  BoundArg1 arg1,
1424  BoundArg2 arg2) {
1425  typedef std::tuple<BoundArg1, BoundArg2> Tuple;
1426  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1427  {t, func, arg1, arg2};
1428 }
1429 
1430 /**
1431  * An alternative function to make Callback::CallbackArg objects,
1432  * which is for use where a target function either receives a class
1433  * type bound argument by value, or receives a bound argument by
1434  * reference to const in a case where the generated CallbackArg object
1435  * is to store a copy of that argument instead of just keeping a
1436  * reference.
1437  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1438  * is exhausted and the system throws in that case (this exception
1439  * will not be thrown if the library has been installed using the
1440  * \--with-glib-memory-slices-no-compat configuration option: instead
1441  * glib will terminate the program if it is unable to obtain memory
1442  * from the operating system). It will also throw if the copy or move
1443  * constructor of a bound argument throws.
1444  *
1445  * Since 2.0.0-rc3
1446  */
1447 template <class T, class BoundArg1, class BoundArg2,
1448  class Arg1, class Arg2, class... FreeArgs>
1449 CallbackArg<FreeArgs...>* make_ref(T& t,
1450  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1451  Arg1&& arg1,
1452  Arg2&& arg2) {
1453  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1454  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type> Tuple;
1455  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1456  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2)};
1457 }
1458 
1459 /**
1460  * A convenience function to make Callback::CallbackArg objects
1461  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1462  * is exhausted and the system throws in that case (this exception
1463  * will not be thrown if the library has been installed using the
1464  * \--with-glib-memory-slices-no-compat configuration option: instead
1465  * glib will terminate the program if it is unable to obtain memory
1466  * from the operating system). It will also throw if the copy
1467  * constructor of a bound argument throws and it is not a reference
1468  * argument.
1469  */
1470 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1471 CallbackArg<FreeArgs...>* make(T& t,
1472  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1473  BoundArg1 arg1,
1474  BoundArg2 arg2,
1475  BoundArg3 arg3) {
1476  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3> Tuple;
1477  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1478  {t, func, arg1, arg2, arg3};
1479 }
1480 
1481 /**
1482  * An alternative function to make Callback::CallbackArg objects,
1483  * which is for use where a target function either receives a class
1484  * type bound argument by value, or receives a bound argument by
1485  * reference to const in a case where the generated CallbackArg object
1486  * is to store a copy of that argument instead of just keeping a
1487  * reference.
1488  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1489  * is exhausted and the system throws in that case (this exception
1490  * will not be thrown if the library has been installed using the
1491  * \--with-glib-memory-slices-no-compat configuration option: instead
1492  * glib will terminate the program if it is unable to obtain memory
1493  * from the operating system). It will also throw if the copy or move
1494  * constructor of a bound argument throws.
1495  *
1496  * Since 2.0.0-rc3
1497  */
1498 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1499  class Arg1, class Arg2, class Arg3, class... FreeArgs>
1500 CallbackArg<FreeArgs...>* make_ref(T& t,
1501  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1502  Arg1&& arg1,
1503  Arg2&& arg2,
1504  Arg3&& arg3) {
1505  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1506  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
1507  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type> Tuple;
1508  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1509  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3)};
1510 }
1511 
1512 /**
1513  * A convenience function to make Callback::CallbackArg objects
1514  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1515  * is exhausted and the system throws in that case (this exception
1516  * will not be thrown if the library has been installed using the
1517  * \--with-glib-memory-slices-no-compat configuration option: instead
1518  * glib will terminate the program if it is unable to obtain memory
1519  * from the operating system). It will also throw if the copy
1520  * constructor of a bound argument throws and it is not a reference
1521  * argument.
1522  */
1523 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1524  class BoundArg4, class... FreeArgs>
1525 CallbackArg<FreeArgs...>* make(T& t,
1526  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1527  BoundArg4, FreeArgs...),
1528  BoundArg1 arg1,
1529  BoundArg2 arg2,
1530  BoundArg3 arg3,
1531  BoundArg4 arg4) {
1532  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4> Tuple;
1533  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1534  {t, func, arg1, arg2, arg3, arg4};
1535 }
1536 
1537 /**
1538  * An alternative function to make Callback::CallbackArg objects,
1539  * which is for use where a target function either receives a class
1540  * type bound argument by value, or receives a bound argument by
1541  * reference to const in a case where the generated CallbackArg object
1542  * is to store a copy of that argument instead of just keeping a
1543  * reference.
1544  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1545  * is exhausted and the system throws in that case (this exception
1546  * will not be thrown if the library has been installed using the
1547  * \--with-glib-memory-slices-no-compat configuration option: instead
1548  * glib will terminate the program if it is unable to obtain memory
1549  * from the operating system). It will also throw if the copy or move
1550  * constructor of a bound argument throws.
1551  *
1552  * Since 2.0.0-rc3
1553  */
1554 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
1555  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
1556 CallbackArg<FreeArgs...>* make_ref(T& t,
1557  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1558  BoundArg4, FreeArgs...),
1559  Arg1&& arg1,
1560  Arg2&& arg2,
1561  Arg3&& arg3,
1562  Arg4&& arg4) {
1563  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1564  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
1565  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
1566  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type> Tuple;
1567  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1568  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2),
1569  std::forward<Arg3>(arg3), std::forward<Arg4>(arg4)};
1570 }
1571 
1572 /**
1573  * A convenience function to make Callback::CallbackArg objects
1574  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1575  * is exhausted and the system throws in that case (this exception
1576  * will not be thrown if the library has been installed using the
1577  * \--with-glib-memory-slices-no-compat configuration option: instead
1578  * glib will terminate the program if it is unable to obtain memory
1579  * from the operating system). It will also throw if the copy
1580  * constructor of a bound argument throws and it is not a reference
1581  * argument.
1582  */
1583 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1584  class BoundArg4, class BoundArg5, class... FreeArgs>
1585 CallbackArg<FreeArgs...>* make(T& t,
1586  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1587  BoundArg4, BoundArg5, FreeArgs...),
1588  BoundArg1 arg1,
1589  BoundArg2 arg2,
1590  BoundArg3 arg3,
1591  BoundArg4 arg4,
1592  BoundArg5 arg5) {
1593  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5> Tuple;
1594  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1595  {t, func, arg1, arg2, arg3, arg4, arg5};
1596 }
1597 
1598 /**
1599  * An alternative function to make Callback::CallbackArg objects,
1600  * which is for use where a target function either receives a class
1601  * type bound argument by value, or receives a bound argument by
1602  * reference to const in a case where the generated CallbackArg object
1603  * is to store a copy of that argument instead of just keeping a
1604  * reference.
1605  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1606  * is exhausted and the system throws in that case (this exception
1607  * will not be thrown if the library has been installed using the
1608  * \--with-glib-memory-slices-no-compat configuration option: instead
1609  * glib will terminate the program if it is unable to obtain memory
1610  * from the operating system). It will also throw if the copy or move
1611  * constructor of a bound argument throws.
1612  *
1613  * Since 2.0.0-rc3
1614  */
1615 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
1616  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
1617 CallbackArg<FreeArgs...>* make_ref(T& t,
1618  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1619  BoundArg4, BoundArg5, FreeArgs...),
1620  Arg1&& arg1,
1621  Arg2&& arg2,
1622  Arg3&& arg3,
1623  Arg4&& arg4,
1624  Arg5&& arg5) {
1625  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1626  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
1627  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
1628  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
1629  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type> Tuple;
1630  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1631  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
1632  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5)};
1633 }
1634 
1635 /**
1636  * A convenience function to make Callback::CallbackArg objects
1637  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1638  * is exhausted and the system throws in that case (this exception
1639  * will not be thrown if the library has been installed using the
1640  * \--with-glib-memory-slices-no-compat configuration option: instead
1641  * glib will terminate the program if it is unable to obtain memory
1642  * from the operating system). It will also throw if the copy
1643  * constructor of a bound argument throws and it is not a reference
1644  * argument.
1645  * @note More than 5 bound values may not be passed to this function
1646  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1647  * >= 3.4, or (ii) the library is compiled by another compiler with
1648  * appropriate support for C++11 tuples using the \--with-tuple
1649  * configuration option.
1650  *
1651  * Since 2.2.10
1652  */
1653 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1654  class BoundArg4, class BoundArg5, class BoundArg6, class... FreeArgs>
1655 CallbackArg<FreeArgs...>* make(T& t,
1656  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1657  BoundArg4, BoundArg5, BoundArg6,
1658  FreeArgs...),
1659  BoundArg1 arg1,
1660  BoundArg2 arg2,
1661  BoundArg3 arg3,
1662  BoundArg4 arg4,
1663  BoundArg5 arg5,
1664  BoundArg6 arg6) {
1665  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
1666  BoundArg5, BoundArg6> Tuple;
1667  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1668  {t, func, arg1, arg2, arg3, arg4, arg5, arg6};
1669 }
1670 
1671 /**
1672  * An alternative function to make Callback::CallbackArg objects,
1673  * which is for use where a target function either receives a class
1674  * type bound argument by value, or receives a bound argument by
1675  * reference to const in a case where the generated CallbackArg object
1676  * is to store a copy of that argument instead of just keeping a
1677  * reference.
1678  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1679  * is exhausted and the system throws in that case (this exception
1680  * will not be thrown if the library has been installed using the
1681  * \--with-glib-memory-slices-no-compat configuration option: instead
1682  * glib will terminate the program if it is unable to obtain memory
1683  * from the operating system). It will also throw if the copy or move
1684  * constructor of a bound argument throws.
1685  * @note More than 5 bound values may not be passed to this function
1686  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1687  * >= 3.4, or (ii) the library is compiled by another compiler with
1688  * appropriate support for C++11 tuples using the \--with-tuple
1689  * configuration option.
1690  *
1691  * Since 2.2.10
1692  */
1693 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
1694  class BoundArg5, class BoundArg6, class Arg1, class Arg2, class Arg3, class Arg4,
1695  class Arg5, class Arg6, class... FreeArgs>
1696 CallbackArg<FreeArgs...>* make_ref(T& t,
1697  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1698  BoundArg4, BoundArg5, BoundArg6,
1699  FreeArgs...),
1700  Arg1&& arg1,
1701  Arg2&& arg2,
1702  Arg3&& arg3,
1703  Arg4&& arg4,
1704  Arg5&& arg5,
1705  Arg6&& arg6) {
1706  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1707  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
1708  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
1709  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
1710  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
1711  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type> Tuple;
1712  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1713  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
1714  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6)};
1715 }
1716 
1717 /**
1718  * A convenience function to make Callback::CallbackArg objects
1719  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1720  * is exhausted and the system throws in that case (this exception
1721  * will not be thrown if the library has been installed using the
1722  * \--with-glib-memory-slices-no-compat configuration option: instead
1723  * glib will terminate the program if it is unable to obtain memory
1724  * from the operating system). It will also throw if the copy
1725  * constructor of a bound argument throws and it is not a reference
1726  * argument.
1727  * @note More than 5 bound values may not be passed to this function
1728  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1729  * >= 3.4, or (ii) the library is compiled by another compiler with
1730  * appropriate support for C++11 tuples using the \--with-tuple
1731  * configuration option.
1732  *
1733  * Since 2.2.10
1734  */
1735 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1736  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
1737  class... FreeArgs>
1738 CallbackArg<FreeArgs...>* make(T& t,
1739  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1740  BoundArg4, BoundArg5, BoundArg6,
1741  BoundArg7, FreeArgs...),
1742  BoundArg1 arg1,
1743  BoundArg2 arg2,
1744  BoundArg3 arg3,
1745  BoundArg4 arg4,
1746  BoundArg5 arg5,
1747  BoundArg6 arg6,
1748  BoundArg7 arg7) {
1749  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
1750  BoundArg5, BoundArg6, BoundArg7> Tuple;
1751  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1752  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7};
1753 }
1754 
1755 /**
1756  * An alternative function to make Callback::CallbackArg objects,
1757  * which is for use where a target function either receives a class
1758  * type bound argument by value, or receives a bound argument by
1759  * reference to const in a case where the generated CallbackArg object
1760  * is to store a copy of that argument instead of just keeping a
1761  * reference.
1762  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1763  * is exhausted and the system throws in that case (this exception
1764  * will not be thrown if the library has been installed using the
1765  * \--with-glib-memory-slices-no-compat configuration option: instead
1766  * glib will terminate the program if it is unable to obtain memory
1767  * from the operating system). It will also throw if the copy or move
1768  * constructor of a bound argument throws.
1769  * @note More than 5 bound values may not be passed to this function
1770  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1771  * >= 3.4, or (ii) the library is compiled by another compiler with
1772  * appropriate support for C++11 tuples using the \--with-tuple
1773  * configuration option.
1774  *
1775  * Since 2.2.10
1776  */
1777 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
1778  class BoundArg5, class BoundArg6, class BoundArg7, class Arg1, class Arg2,
1779  class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class... FreeArgs>
1780 CallbackArg<FreeArgs...>* make_ref(T& t,
1781  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1782  BoundArg4, BoundArg5, BoundArg6,
1783  BoundArg7, FreeArgs...),
1784  Arg1&& arg1,
1785  Arg2&& arg2,
1786  Arg3&& arg3,
1787  Arg4&& arg4,
1788  Arg5&& arg5,
1789  Arg6&& arg6,
1790  Arg7&& arg7) {
1791  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1792  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
1793  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
1794  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
1795  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
1796  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
1797  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type> Tuple;
1798  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1799  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
1800  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
1801  std::forward<Arg7>(arg7)};
1802 }
1803 
1804 /**
1805  * A convenience function to make Callback::CallbackArg objects
1806  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1807  * is exhausted and the system throws in that case (this exception
1808  * will not be thrown if the library has been installed using the
1809  * \--with-glib-memory-slices-no-compat configuration option: instead
1810  * glib will terminate the program if it is unable to obtain memory
1811  * from the operating system). It will also throw if the copy
1812  * constructor of a bound argument throws and it is not a reference
1813  * argument.
1814  * @note More than 5 bound values may not be passed to this function
1815  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1816  * >= 3.4, or (ii) the library is compiled by another compiler with
1817  * appropriate support for C++11 tuples using the \--with-tuple
1818  * configuration option.
1819  *
1820  * Since 2.2.10
1821  */
1822 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1823  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
1824  class BoundArg8, class... FreeArgs>
1825 CallbackArg<FreeArgs...>* make(T& t,
1826  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1827  BoundArg4, BoundArg5, BoundArg6,
1828  BoundArg7, BoundArg8, FreeArgs...),
1829  BoundArg1 arg1,
1830  BoundArg2 arg2,
1831  BoundArg3 arg3,
1832  BoundArg4 arg4,
1833  BoundArg5 arg5,
1834  BoundArg6 arg6,
1835  BoundArg7 arg7,
1836  BoundArg8 arg8) {
1837  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
1838  BoundArg5, BoundArg6, BoundArg7, BoundArg8> Tuple;
1839  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1840  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
1841 }
1842 
1843 /**
1844  * An alternative function to make Callback::CallbackArg objects,
1845  * which is for use where a target function either receives a class
1846  * type bound argument by value, or receives a bound argument by
1847  * reference to const in a case where the generated CallbackArg object
1848  * is to store a copy of that argument instead of just keeping a
1849  * reference.
1850  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1851  * is exhausted and the system throws in that case (this exception
1852  * will not be thrown if the library has been installed using the
1853  * \--with-glib-memory-slices-no-compat configuration option: instead
1854  * glib will terminate the program if it is unable to obtain memory
1855  * from the operating system). It will also throw if the copy or move
1856  * constructor of a bound argument throws.
1857  * @note More than 5 bound values may not be passed to this function
1858  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1859  * >= 3.4, or (ii) the library is compiled by another compiler with
1860  * appropriate support for C++11 tuples using the \--with-tuple
1861  * configuration option.
1862  *
1863  * Since 2.2.10
1864  */
1865 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
1866  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8, class Arg1,
1867  class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8,
1868  class... FreeArgs>
1869 CallbackArg<FreeArgs...>* make_ref(T& t,
1870  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1871  BoundArg4, BoundArg5, BoundArg6,
1872  BoundArg7, BoundArg8, FreeArgs...),
1873  Arg1&& arg1,
1874  Arg2&& arg2,
1875  Arg3&& arg3,
1876  Arg4&& arg4,
1877  Arg5&& arg5,
1878  Arg6&& arg6,
1879  Arg7&& arg7,
1880  Arg8&& arg8) {
1881  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1882  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
1883  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
1884  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
1885  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
1886  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
1887  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
1888  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type> Tuple;
1889  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1890  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
1891  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
1892  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8)};
1893 }
1894 
1895 /**
1896  * A convenience function to make Callback::CallbackArg objects
1897  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1898  * is exhausted and the system throws in that case (this exception
1899  * will not be thrown if the library has been installed using the
1900  * \--with-glib-memory-slices-no-compat configuration option: instead
1901  * glib will terminate the program if it is unable to obtain memory
1902  * from the operating system). It will also throw if the copy
1903  * constructor of a bound argument throws and it is not a reference
1904  * argument.
1905  * @note More than 5 bound values may not be passed to this function
1906  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1907  * >= 3.4, or (ii) the library is compiled by another compiler with
1908  * appropriate support for C++11 tuples using the \--with-tuple
1909  * configuration option.
1910  *
1911  * Since 2.2.10
1912  */
1913 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1914  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
1915  class BoundArg8, class BoundArg9, class... FreeArgs>
1916 CallbackArg<FreeArgs...>* make(T& t,
1917  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1918  BoundArg4, BoundArg5, BoundArg6,
1919  BoundArg7, BoundArg8, BoundArg9,
1920  FreeArgs...),
1921  BoundArg1 arg1,
1922  BoundArg2 arg2,
1923  BoundArg3 arg3,
1924  BoundArg4 arg4,
1925  BoundArg5 arg5,
1926  BoundArg6 arg6,
1927  BoundArg7 arg7,
1928  BoundArg8 arg8,
1929  BoundArg9 arg9) {
1930  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
1931  BoundArg5, BoundArg6, BoundArg7, BoundArg8,
1932  BoundArg9> Tuple;
1933  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1934  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9};
1935 }
1936 
1937 /**
1938  * An alternative function to make Callback::CallbackArg objects,
1939  * which is for use where a target function either receives a class
1940  * type bound argument by value, or receives a bound argument by
1941  * reference to const in a case where the generated CallbackArg object
1942  * is to store a copy of that argument instead of just keeping a
1943  * reference.
1944  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1945  * is exhausted and the system throws in that case (this exception
1946  * will not be thrown if the library has been installed using the
1947  * \--with-glib-memory-slices-no-compat configuration option: instead
1948  * glib will terminate the program if it is unable to obtain memory
1949  * from the operating system). It will also throw if the copy or move
1950  * constructor of a bound argument throws.
1951  * @note More than 5 bound values may not be passed to this function
1952  * unless either (i) this library is compiled with gcc >= 4.8 or clang
1953  * >= 3.4, or (ii) the library is compiled by another compiler with
1954  * appropriate support for C++11 tuples using the \--with-tuple
1955  * configuration option.
1956  *
1957  * Since 2.2.10
1958  */
1959 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
1960  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8, class BoundArg9,
1961  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7,
1962  class Arg8, class Arg9, class... FreeArgs>
1963 CallbackArg<FreeArgs...>* make_ref(T& t,
1964  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1965  BoundArg4, BoundArg5, BoundArg6,
1966  BoundArg7, BoundArg8, BoundArg9,
1967  FreeArgs...),
1968  Arg1&& arg1,
1969  Arg2&& arg2,
1970  Arg3&& arg3,
1971  Arg4&& arg4,
1972  Arg5&& arg5,
1973  Arg6&& arg6,
1974  Arg7&& arg7,
1975  Arg8&& arg8,
1976  Arg9&& arg9) {
1977  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
1978  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
1979  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
1980  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
1981  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
1982  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
1983  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
1984  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type,
1985  typename std::remove_const<typename std::remove_reference<BoundArg9>::type>::type> Tuple;
1986  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
1987  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
1988  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
1989  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8), std::forward<Arg9>(arg9)};
1990 }
1991 
1992 /**
1993  * A convenience function to make Callback::CallbackArg objects
1994  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1995  * is exhausted and the system throws in that case (this exception
1996  * will not be thrown if the library has been installed using the
1997  * \--with-glib-memory-slices-no-compat configuration option: instead
1998  * glib will terminate the program if it is unable to obtain memory
1999  * from the operating system). It will also throw if the copy
2000  * constructor of a bound argument throws and it is not a reference
2001  * argument.
2002  * @note More than 5 bound values may not be passed to this function
2003  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2004  * >= 3.4, or (ii) the library is compiled by another compiler with
2005  * appropriate support for C++11 tuples using the \--with-tuple
2006  * configuration option.
2007  *
2008  * Since 2.2.10
2009  */
2010 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2011  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
2012  class BoundArg8, class BoundArg9, class BoundArg10, class... FreeArgs>
2013 CallbackArg<FreeArgs...>* make(T& t,
2014  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2015  BoundArg4, BoundArg5, BoundArg6,
2016  BoundArg7, BoundArg8, BoundArg9,
2017  BoundArg10, FreeArgs...),
2018  BoundArg1 arg1,
2019  BoundArg2 arg2,
2020  BoundArg3 arg3,
2021  BoundArg4 arg4,
2022  BoundArg5 arg5,
2023  BoundArg6 arg6,
2024  BoundArg7 arg7,
2025  BoundArg8 arg8,
2026  BoundArg9 arg9,
2027  BoundArg10 arg10) {
2028  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
2029  BoundArg5, BoundArg6, BoundArg7, BoundArg8,
2030  BoundArg9, BoundArg10> Tuple;
2031  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
2032  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
2033 }
2034 
2035 /**
2036  * An alternative function to make Callback::CallbackArg objects,
2037  * which is for use where a target function either receives a class
2038  * type bound argument by value, or receives a bound argument by
2039  * reference to const in a case where the generated CallbackArg object
2040  * is to store a copy of that argument instead of just keeping a
2041  * reference.
2042  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2043  * is exhausted and the system throws in that case (this exception
2044  * will not be thrown if the library has been installed using the
2045  * \--with-glib-memory-slices-no-compat configuration option: instead
2046  * glib will terminate the program if it is unable to obtain memory
2047  * from the operating system). It will also throw if the copy or move
2048  * constructor of a bound argument throws.
2049  * @note More than 5 bound values may not be passed to this function
2050  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2051  * >= 3.4, or (ii) the library is compiled by another compiler with
2052  * appropriate support for C++11 tuples using the \--with-tuple
2053  * configuration option.
2054  *
2055  * Since 2.2.10
2056  */
2057 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2058  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8, class BoundArg9,
2059  class BoundArg10, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6,
2060  class Arg7, class Arg8, class Arg9, class Arg10, class... FreeArgs>
2061 CallbackArg<FreeArgs...>* make_ref(T& t,
2062  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2063  BoundArg4, BoundArg5, BoundArg6,
2064  BoundArg7, BoundArg8, BoundArg9,
2065  BoundArg10, FreeArgs...),
2066  Arg1&& arg1,
2067  Arg2&& arg2,
2068  Arg3&& arg3,
2069  Arg4&& arg4,
2070  Arg5&& arg5,
2071  Arg6&& arg6,
2072  Arg7&& arg7,
2073  Arg8&& arg8,
2074  Arg9&& arg9,
2075  Arg10&& arg10) {
2076  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2077  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2078  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2079  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
2080  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
2081  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
2082  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
2083  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type,
2084  typename std::remove_const<typename std::remove_reference<BoundArg9>::type>::type,
2085  typename std::remove_const<typename std::remove_reference<BoundArg10>::type>::type> Tuple;
2086  return new Callback_memfun_tuple<T, decltype(func), Tuple, FreeArgs...>
2087  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
2088  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
2089  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8), std::forward<Arg9>(arg9),
2090  std::forward<Arg10>(arg10)};
2091 }
2092 
2093 /* const versions, for binding to const methods */
2094 
2095 /**
2096  * A convenience function to make Callback::CallbackArg objects
2097  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2098  * is exhausted and the system throws in that case. This exception
2099  * will not be thrown if the library has been installed using the
2100  * \--with-glib-memory-slices-no-compat configuration option (instead
2101  * glib will terminate the program if it is unable to obtain memory
2102  * from the operating system).
2103  */
2104 template <class T, class... FreeArgs>
2105 CallbackArg<FreeArgs...>* make(const T& t,
2106  void (T::*func)(FreeArgs...) const) {
2107  return new Callback_memfun<const T, decltype(func), FreeArgs...>{t, func};
2108 }
2109 
2110 /**
2111  * Since this function constructs a callback which does not take a
2112  * bound argument, it is a synonym for make() (the two are identical).
2113  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2114  * is exhausted and the system throws in that case. This exception
2115  * will not be thrown if the library has been installed using the
2116  * \--with-glib-memory-slices-no-compat configuration option (instead
2117  * glib will terminate the program if it is unable to obtain memory
2118  * from the operating system).
2119  *
2120  * Since 2.0.0-rc3
2121  */
2122 template <class T, class... FreeArgs>
2123 CallbackArg<FreeArgs...>* make_ref(const T& t,
2124  void (T::*func)(FreeArgs...) const) {
2125  return new Callback_memfun<const T, decltype(func), FreeArgs...>{t, func};
2126 }
2127 
2128 /**
2129  * A convenience function to make Callback::CallbackArg objects
2130  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2131  * is exhausted and the system throws in that case (this exception
2132  * will not be thrown if the library has been installed using the
2133  * \--with-glib-memory-slices-no-compat configuration option: instead
2134  * glib will terminate the program if it is unable to obtain memory
2135  * from the operating system). It will also throw if the copy
2136  * constructor of a bound argument throws and it is not a reference
2137  * argument.
2138  */
2139 template <class T, class BoundArg, class... FreeArgs>
2140 CallbackArg<FreeArgs...>* make(const T& t,
2141  void (T::*func)(BoundArg, FreeArgs...) const,
2142  BoundArg arg) {
2143  typedef std::tuple<BoundArg> Tuple;
2144  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2145  {t, func, arg};
2146 }
2147 
2148 /**
2149  * An alternative function to make Callback::CallbackArg objects,
2150  * which is for use where a target function either receives a class
2151  * type bound argument by value, or receives a bound argument by
2152  * reference to const in a case where the generated CallbackArg object
2153  * is to store a copy of that argument instead of just keeping a
2154  * reference.
2155  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2156  * is exhausted and the system throws in that case (this exception
2157  * will not be thrown if the library has been installed using the
2158  * \--with-glib-memory-slices-no-compat configuration option: instead
2159  * glib will terminate the program if it is unable to obtain memory
2160  * from the operating system). It will also throw if the copy or move
2161  * constructor of a bound argument throws.
2162  *
2163  * Since 2.0.0-rc3
2164  */
2165 template <class T, class BoundArg, class Arg, class... FreeArgs>
2166 CallbackArg<FreeArgs...>* make_ref(const T& t,
2167  void (T::*func)(BoundArg, FreeArgs...) const,
2168  Arg&& arg) {
2169  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg>::type>::type> Tuple;
2170  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2171  {t, func, std::forward<Arg>(arg)};
2172 }
2173 
2174 /**
2175  * A convenience function to make Callback::CallbackArg objects
2176  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2177  * is exhausted and the system throws in that case (this exception
2178  * will not be thrown if the library has been installed using the
2179  * \--with-glib-memory-slices-no-compat configuration option: instead
2180  * glib will terminate the program if it is unable to obtain memory
2181  * from the operating system). It will also throw if the copy
2182  * constructor of a bound argument throws and it is not a reference
2183  * argument.
2184  */
2185 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
2186 CallbackArg<FreeArgs...>* make(const T& t,
2187  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2188  BoundArg1 arg1,
2189  BoundArg2 arg2) {
2190  typedef std::tuple<BoundArg1, BoundArg2> Tuple;
2191  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2192  {t, func, arg1, arg2};
2193 }
2194 
2195 /**
2196  * An alternative function to make Callback::CallbackArg objects,
2197  * which is for use where a target function either receives a class
2198  * type bound argument by value, or receives a bound argument by
2199  * reference to const in a case where the generated CallbackArg object
2200  * is to store a copy of that argument instead of just keeping a
2201  * reference.
2202  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2203  * is exhausted and the system throws in that case (this exception
2204  * will not be thrown if the library has been installed using the
2205  * \--with-glib-memory-slices-no-compat configuration option: instead
2206  * glib will terminate the program if it is unable to obtain memory
2207  * from the operating system). It will also throw if the copy or move
2208  * constructor of a bound argument throws.
2209  *
2210  * Since 2.0.0-rc3
2211  */
2212 template <class T, class BoundArg1, class BoundArg2,
2213  class Arg1, class Arg2, class... FreeArgs>
2214 CallbackArg<FreeArgs...>* make_ref(const T& t,
2215  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2216  Arg1&& arg1,
2217  Arg2&& arg2) {
2218  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2219  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type> Tuple;
2220  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2221  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2)};
2222 }
2223 
2224 /**
2225  * A convenience function to make Callback::CallbackArg objects
2226  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2227  * is exhausted and the system throws in that case (this exception
2228  * will not be thrown if the library has been installed using the
2229  * \--with-glib-memory-slices-no-compat configuration option: instead
2230  * glib will terminate the program if it is unable to obtain memory
2231  * from the operating system). It will also throw if the copy
2232  * constructor of a bound argument throws and it is not a reference
2233  * argument.
2234  */
2235 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2236 CallbackArg<FreeArgs...>* make(const T& t,
2237  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2238  BoundArg1 arg1,
2239  BoundArg2 arg2,
2240  BoundArg3 arg3) {
2241  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3> Tuple;
2242  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2243  {t, func, arg1, arg2, arg3};
2244 }
2245 
2246 /**
2247  * An alternative function to make Callback::CallbackArg objects,
2248  * which is for use where a target function either receives a class
2249  * type bound argument by value, or receives a bound argument by
2250  * reference to const in a case where the generated CallbackArg object
2251  * is to store a copy of that argument instead of just keeping a
2252  * reference.
2253  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2254  * is exhausted and the system throws in that case (this exception
2255  * will not be thrown if the library has been installed using the
2256  * \--with-glib-memory-slices-no-compat configuration option: instead
2257  * glib will terminate the program if it is unable to obtain memory
2258  * from the operating system). It will also throw if the copy or move
2259  * constructor of a bound argument throws.
2260  *
2261  * Since 2.0.0-rc3
2262  */
2263 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2264  class Arg1, class Arg2, class Arg3, class... FreeArgs>
2265 CallbackArg<FreeArgs...>* make_ref(const T& t,
2266  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2267  Arg1&& arg1,
2268  Arg2&& arg2,
2269  Arg3&& arg3) {
2270  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2271  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2272  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type> Tuple;
2273  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2274  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3)};
2275 }
2276 
2277 /**
2278  * A convenience function to make Callback::CallbackArg objects
2279  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2280  * is exhausted and the system throws in that case (this exception
2281  * will not be thrown if the library has been installed using the
2282  * \--with-glib-memory-slices-no-compat configuration option: instead
2283  * glib will terminate the program if it is unable to obtain memory
2284  * from the operating system). It will also throw if the copy
2285  * constructor of a bound argument throws and it is not a reference
2286  * argument.
2287  */
2288 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2289  class BoundArg4, class... FreeArgs>
2290 CallbackArg<FreeArgs...>* make(const T& t,
2291  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2292  BoundArg4, FreeArgs...) const,
2293  BoundArg1 arg1,
2294  BoundArg2 arg2,
2295  BoundArg3 arg3,
2296  BoundArg4 arg4) {
2297  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4> Tuple;
2298  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2299  {t, func, arg1, arg2, arg3, arg4};
2300 }
2301 
2302 /**
2303  * An alternative function to make Callback::CallbackArg objects,
2304  * which is for use where a target function either receives a class
2305  * type bound argument by value, or receives a bound argument by
2306  * reference to const in a case where the generated CallbackArg object
2307  * is to store a copy of that argument instead of just keeping a
2308  * reference.
2309  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2310  * is exhausted and the system throws in that case (this exception
2311  * will not be thrown if the library has been installed using the
2312  * \--with-glib-memory-slices-no-compat configuration option: instead
2313  * glib will terminate the program if it is unable to obtain memory
2314  * from the operating system). It will also throw if the copy or move
2315  * constructor of a bound argument throws.
2316  *
2317  * Since 2.0.0-rc3
2318  */
2319 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2320  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
2321 CallbackArg<FreeArgs...>* make_ref(const T& t,
2322  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2323  BoundArg4, FreeArgs...) const,
2324  Arg1&& arg1,
2325  Arg2&& arg2,
2326  Arg3&& arg3,
2327  Arg4&& arg4) {
2328  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2329  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2330  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2331  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type> Tuple;
2332  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2333  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2),
2334  std::forward<Arg3>(arg3), std::forward<Arg4>(arg4)};
2335 }
2336 
2337 /**
2338  * A convenience function to make Callback::CallbackArg objects
2339  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2340  * is exhausted and the system throws in that case (this exception
2341  * will not be thrown if the library has been installed using the
2342  * \--with-glib-memory-slices-no-compat configuration option: instead
2343  * glib will terminate the program if it is unable to obtain memory
2344  * from the operating system). It will also throw if the copy
2345  * constructor of a bound argument throws and it is not a reference
2346  * argument.
2347  */
2348 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2349  class BoundArg4, class BoundArg5, class... FreeArgs>
2350 CallbackArg<FreeArgs...>* make(const T& t,
2351  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2352  BoundArg4, BoundArg5, FreeArgs...) const,
2353  BoundArg1 arg1,
2354  BoundArg2 arg2,
2355  BoundArg3 arg3,
2356  BoundArg4 arg4,
2357  BoundArg5 arg5) {
2358  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5> Tuple;
2359  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2360  {t, func, arg1, arg2, arg3, arg4, arg5};
2361 }
2362 
2363 /**
2364  * An alternative function to make Callback::CallbackArg objects,
2365  * which is for use where a target function either receives a class
2366  * type bound argument by value, or receives a bound argument by
2367  * reference to const in a case where the generated CallbackArg object
2368  * is to store a copy of that argument instead of just keeping a
2369  * reference.
2370  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2371  * is exhausted and the system throws in that case (this exception
2372  * will not be thrown if the library has been installed using the
2373  * \--with-glib-memory-slices-no-compat configuration option: instead
2374  * glib will terminate the program if it is unable to obtain memory
2375  * from the operating system). It will also throw if the copy or move
2376  * constructor of a bound argument throws.
2377  *
2378  * Since 2.0.0-rc3
2379  */
2380 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
2381  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
2382 CallbackArg<FreeArgs...>* make_ref(const T& t,
2383  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2384  BoundArg4, BoundArg5, FreeArgs...) const,
2385  Arg1&& arg1,
2386  Arg2&& arg2,
2387  Arg3&& arg3,
2388  Arg4&& arg4,
2389  Arg5&& arg5) {
2390  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2391  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2392  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2393  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
2394  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type> Tuple;
2395  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2396  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
2397  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5)};
2398 }
2399 
2400 /**
2401  * A convenience function to make Callback::CallbackArg objects
2402  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2403  * is exhausted and the system throws in that case (this exception
2404  * will not be thrown if the library has been installed using the
2405  * \--with-glib-memory-slices-no-compat configuration option: instead
2406  * glib will terminate the program if it is unable to obtain memory
2407  * from the operating system). It will also throw if the copy
2408  * constructor of a bound argument throws and it is not a reference
2409  * argument.
2410  * @note More than 5 bound values may not be passed to this function
2411  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2412  * >= 3.4, or (ii) the library is compiled by another compiler with
2413  * appropriate support for C++11 tuples using the \--with-tuple
2414  * configuration option.
2415  *
2416  * Since 2.2.10
2417  */
2418 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2419  class BoundArg4, class BoundArg5, class BoundArg6, class... FreeArgs>
2420 CallbackArg<FreeArgs...>* make(const T& t,
2421  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2422  BoundArg4, BoundArg5, BoundArg6,
2423  FreeArgs...) const,
2424  BoundArg1 arg1,
2425  BoundArg2 arg2,
2426  BoundArg3 arg3,
2427  BoundArg4 arg4,
2428  BoundArg5 arg5,
2429  BoundArg6 arg6) {
2430  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
2431  BoundArg5, BoundArg6> Tuple;
2432  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2433  {t, func, arg1, arg2, arg3, arg4, arg5, arg6};
2434 }
2435 
2436 /**
2437  * An alternative function to make Callback::CallbackArg objects,
2438  * which is for use where a target function either receives a class
2439  * type bound argument by value, or receives a bound argument by
2440  * reference to const in a case where the generated CallbackArg object
2441  * is to store a copy of that argument instead of just keeping a
2442  * reference.
2443  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2444  * is exhausted and the system throws in that case (this exception
2445  * will not be thrown if the library has been installed using the
2446  * \--with-glib-memory-slices-no-compat configuration option: instead
2447  * glib will terminate the program if it is unable to obtain memory
2448  * from the operating system). It will also throw if the copy or move
2449  * constructor of a bound argument throws.
2450  * @note More than 5 bound values may not be passed to this function
2451  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2452  * >= 3.4, or (ii) the library is compiled by another compiler with
2453  * appropriate support for C++11 tuples using the \--with-tuple
2454  * configuration option.
2455  *
2456  * Since 2.2.10
2457  */
2458 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2459  class BoundArg5, class BoundArg6, class Arg1, class Arg2, class Arg3, class Arg4,
2460  class Arg5, class Arg6, class... FreeArgs>
2461 CallbackArg<FreeArgs...>* make_ref(const T& t,
2462  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2463  BoundArg4, BoundArg5, BoundArg6,
2464  FreeArgs...) const,
2465  Arg1&& arg1,
2466  Arg2&& arg2,
2467  Arg3&& arg3,
2468  Arg4&& arg4,
2469  Arg5&& arg5,
2470  Arg6&& arg6) {
2471  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2472  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2473  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2474  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
2475  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
2476  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type> Tuple;
2477  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2478  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
2479  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6)};
2480 }
2481 
2482 /**
2483  * A convenience function to make Callback::CallbackArg objects
2484  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2485  * is exhausted and the system throws in that case (this exception
2486  * will not be thrown if the library has been installed using the
2487  * \--with-glib-memory-slices-no-compat configuration option: instead
2488  * glib will terminate the program if it is unable to obtain memory
2489  * from the operating system). It will also throw if the copy
2490  * constructor of a bound argument throws and it is not a reference
2491  * argument.
2492  * @note More than 5 bound values may not be passed to this function
2493  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2494  * >= 3.4, or (ii) the library is compiled by another compiler with
2495  * appropriate support for C++11 tuples using the \--with-tuple
2496  * configuration option.
2497  *
2498  * Since 2.2.10
2499  */
2500 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2501  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
2502  class... FreeArgs>
2503 CallbackArg<FreeArgs...>* make(const T& t,
2504  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2505  BoundArg4, BoundArg5, BoundArg6,
2506  BoundArg7, FreeArgs...) const,
2507  BoundArg1 arg1,
2508  BoundArg2 arg2,
2509  BoundArg3 arg3,
2510  BoundArg4 arg4,
2511  BoundArg5 arg5,
2512  BoundArg6 arg6,
2513  BoundArg7 arg7) {
2514  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
2515  BoundArg5, BoundArg6, BoundArg7> Tuple;
2516  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2517  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7};
2518 }
2519 
2520 /**
2521  * An alternative function to make Callback::CallbackArg objects,
2522  * which is for use where a target function either receives a class
2523  * type bound argument by value, or receives a bound argument by
2524  * reference to const in a case where the generated CallbackArg object
2525  * is to store a copy of that argument instead of just keeping a
2526  * reference.
2527  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2528  * is exhausted and the system throws in that case (this exception
2529  * will not be thrown if the library has been installed using the
2530  * \--with-glib-memory-slices-no-compat configuration option: instead
2531  * glib will terminate the program if it is unable to obtain memory
2532  * from the operating system). It will also throw if the copy or move
2533  * constructor of a bound argument throws.
2534  * @note More than 5 bound values may not be passed to this function
2535  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2536  * >= 3.4, or (ii) the library is compiled by another compiler with
2537  * appropriate support for C++11 tuples using the \--with-tuple
2538  * configuration option.
2539  *
2540  * Since 2.2.10
2541  */
2542 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2543  class BoundArg5, class BoundArg6, class BoundArg7, class Arg1, class Arg2,
2544  class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class... FreeArgs>
2545 CallbackArg<FreeArgs...>* make_ref(const T& t,
2546  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2547  BoundArg4, BoundArg5, BoundArg6,
2548  BoundArg7, FreeArgs...) const,
2549  Arg1&& arg1,
2550  Arg2&& arg2,
2551  Arg3&& arg3,
2552  Arg4&& arg4,
2553  Arg5&& arg5,
2554  Arg6&& arg6,
2555  Arg7&& arg7) {
2556  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2557  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2558  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2559  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
2560  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
2561  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
2562  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type> Tuple;
2563  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2564  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
2565  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
2566  std::forward<Arg7>(arg7)};
2567 }
2568 
2569 /**
2570  * A convenience function to make Callback::CallbackArg objects
2571  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2572  * is exhausted and the system throws in that case (this exception
2573  * will not be thrown if the library has been installed using the
2574  * \--with-glib-memory-slices-no-compat configuration option: instead
2575  * glib will terminate the program if it is unable to obtain memory
2576  * from the operating system). It will also throw if the copy
2577  * constructor of a bound argument throws and it is not a reference
2578  * argument.
2579  * @note More than 5 bound values may not be passed to this function
2580  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2581  * >= 3.4, or (ii) the library is compiled by another compiler with
2582  * appropriate support for C++11 tuples using the \--with-tuple
2583  * configuration option.
2584  *
2585  * Since 2.2.10
2586  */
2587 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2588  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
2589  class BoundArg8, class... FreeArgs>
2590 CallbackArg<FreeArgs...>* make(const T& t,
2591  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2592  BoundArg4, BoundArg5, BoundArg6,
2593  BoundArg7, BoundArg8, FreeArgs...) const,
2594  BoundArg1 arg1,
2595  BoundArg2 arg2,
2596  BoundArg3 arg3,
2597  BoundArg4 arg4,
2598  BoundArg5 arg5,
2599  BoundArg6 arg6,
2600  BoundArg7 arg7,
2601  BoundArg8 arg8) {
2602  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
2603  BoundArg5, BoundArg6, BoundArg7, BoundArg8> Tuple;
2604  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2605  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
2606 }
2607 
2608 /**
2609  * An alternative function to make Callback::CallbackArg objects,
2610  * which is for use where a target function either receives a class
2611  * type bound argument by value, or receives a bound argument by
2612  * reference to const in a case where the generated CallbackArg object
2613  * is to store a copy of that argument instead of just keeping a
2614  * reference.
2615  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2616  * is exhausted and the system throws in that case (this exception
2617  * will not be thrown if the library has been installed using the
2618  * \--with-glib-memory-slices-no-compat configuration option: instead
2619  * glib will terminate the program if it is unable to obtain memory
2620  * from the operating system). It will also throw if the copy or move
2621  * constructor of a bound argument throws.
2622  * @note More than 5 bound values may not be passed to this function
2623  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2624  * >= 3.4, or (ii) the library is compiled by another compiler with
2625  * appropriate support for C++11 tuples using the \--with-tuple
2626  * configuration option.
2627  *
2628  * Since 2.2.10
2629  */
2630 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2631  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8, class Arg1,
2632  class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8,
2633  class... FreeArgs>
2634 CallbackArg<FreeArgs...>* make_ref(const T& t,
2635  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2636  BoundArg4, BoundArg5, BoundArg6,
2637  BoundArg7, BoundArg8, FreeArgs...) const,
2638  Arg1&& arg1,
2639  Arg2&& arg2,
2640  Arg3&& arg3,
2641  Arg4&& arg4,
2642  Arg5&& arg5,
2643  Arg6&& arg6,
2644  Arg7&& arg7,
2645  Arg8&& arg8) {
2646  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2647  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2648  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2649  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
2650  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
2651  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
2652  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
2653  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type> Tuple;
2654  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2655  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
2656  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
2657  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8)};
2658 }
2659 
2660 /**
2661  * A convenience function to make Callback::CallbackArg objects
2662  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2663  * is exhausted and the system throws in that case (this exception
2664  * will not be thrown if the library has been installed using the
2665  * \--with-glib-memory-slices-no-compat configuration option: instead
2666  * glib will terminate the program if it is unable to obtain memory
2667  * from the operating system). It will also throw if the copy
2668  * constructor of a bound argument throws and it is not a reference
2669  * argument.
2670  * @note More than 5 bound values may not be passed to this function
2671  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2672  * >= 3.4, or (ii) the library is compiled by another compiler with
2673  * appropriate support for C++11 tuples using the \--with-tuple
2674  * configuration option.
2675  *
2676  * Since 2.2.10
2677  */
2678 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2679  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
2680  class BoundArg8, class BoundArg9, class... FreeArgs>
2681 CallbackArg<FreeArgs...>* make(const T& t,
2682  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2683  BoundArg4, BoundArg5, BoundArg6,
2684  BoundArg7, BoundArg8, BoundArg9,
2685  FreeArgs...) const,
2686  BoundArg1 arg1,
2687  BoundArg2 arg2,
2688  BoundArg3 arg3,
2689  BoundArg4 arg4,
2690  BoundArg5 arg5,
2691  BoundArg6 arg6,
2692  BoundArg7 arg7,
2693  BoundArg8 arg8,
2694  BoundArg9 arg9) {
2695  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
2696  BoundArg5, BoundArg6, BoundArg7, BoundArg8,
2697  BoundArg9> Tuple;
2698  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2699  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9};
2700 }
2701 
2702 /**
2703  * An alternative function to make Callback::CallbackArg objects,
2704  * which is for use where a target function either receives a class
2705  * type bound argument by value, or receives a bound argument by
2706  * reference to const in a case where the generated CallbackArg object
2707  * is to store a copy of that argument instead of just keeping a
2708  * reference.
2709  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2710  * is exhausted and the system throws in that case (this exception
2711  * will not be thrown if the library has been installed using the
2712  * \--with-glib-memory-slices-no-compat configuration option: instead
2713  * glib will terminate the program if it is unable to obtain memory
2714  * from the operating system). It will also throw if the copy or move
2715  * constructor of a bound argument throws.
2716  * @note More than 5 bound values may not be passed to this function
2717  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2718  * >= 3.4, or (ii) the library is compiled by another compiler with
2719  * appropriate support for C++11 tuples using the \--with-tuple
2720  * configuration option.
2721  *
2722  * Since 2.2.10
2723  */
2724 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2725  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8, class BoundArg9,
2726  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7,
2727  class Arg8, class Arg9, class... FreeArgs>
2728 CallbackArg<FreeArgs...>* make_ref(const T& t,
2729  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2730  BoundArg4, BoundArg5, BoundArg6,
2731  BoundArg7, BoundArg8, BoundArg9,
2732  FreeArgs...) const,
2733  Arg1&& arg1,
2734  Arg2&& arg2,
2735  Arg3&& arg3,
2736  Arg4&& arg4,
2737  Arg5&& arg5,
2738  Arg6&& arg6,
2739  Arg7&& arg7,
2740  Arg8&& arg8,
2741  Arg9&& arg9) {
2742  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2743  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2744  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2745  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
2746  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
2747  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
2748  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
2749  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type,
2750  typename std::remove_const<typename std::remove_reference<BoundArg9>::type>::type> Tuple;
2751  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2752  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
2753  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
2754  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8), std::forward<Arg9>(arg9)};
2755 }
2756 
2757 /**
2758  * A convenience function to make Callback::CallbackArg objects
2759  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2760  * is exhausted and the system throws in that case (this exception
2761  * will not be thrown if the library has been installed using the
2762  * \--with-glib-memory-slices-no-compat configuration option: instead
2763  * glib will terminate the program if it is unable to obtain memory
2764  * from the operating system). It will also throw if the copy
2765  * constructor of a bound argument throws and it is not a reference
2766  * argument.
2767  * @note More than 5 bound values may not be passed to this function
2768  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2769  * >= 3.4, or (ii) the library is compiled by another compiler with
2770  * appropriate support for C++11 tuples using the \--with-tuple
2771  * configuration option.
2772  *
2773  * Since 2.2.10
2774  */
2775 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2776  class BoundArg4, class BoundArg5, class BoundArg6, class BoundArg7,
2777  class BoundArg8, class BoundArg9, class BoundArg10, class... FreeArgs>
2778 CallbackArg<FreeArgs...>* make(const T& t,
2779  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2780  BoundArg4, BoundArg5, BoundArg6,
2781  BoundArg7, BoundArg8, BoundArg9,
2782  BoundArg10, FreeArgs...) const,
2783  BoundArg1 arg1,
2784  BoundArg2 arg2,
2785  BoundArg3 arg3,
2786  BoundArg4 arg4,
2787  BoundArg5 arg5,
2788  BoundArg6 arg6,
2789  BoundArg7 arg7,
2790  BoundArg8 arg8,
2791  BoundArg9 arg9,
2792  BoundArg10 arg10) {
2793  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
2794  BoundArg5, BoundArg6, BoundArg7, BoundArg8,
2795  BoundArg9, BoundArg10> Tuple;
2796  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2797  {t, func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
2798 }
2799 
2800 /**
2801  * An alternative function to make Callback::CallbackArg objects,
2802  * which is for use where a target function either receives a class
2803  * type bound argument by value, or receives a bound argument by
2804  * reference to const in a case where the generated CallbackArg object
2805  * is to store a copy of that argument instead of just keeping a
2806  * reference.
2807  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2808  * is exhausted and the system throws in that case (this exception
2809  * will not be thrown if the library has been installed using the
2810  * \--with-glib-memory-slices-no-compat configuration option: instead
2811  * glib will terminate the program if it is unable to obtain memory
2812  * from the operating system). It will also throw if the copy or move
2813  * constructor of a bound argument throws.
2814  * @note More than 5 bound values may not be passed to this function
2815  * unless either (i) this library is compiled with gcc >= 4.8 or clang
2816  * >= 3.4, or (ii) the library is compiled by another compiler with
2817  * appropriate support for C++11 tuples using the \--with-tuple
2818  * configuration option.
2819  *
2820  * Since 2.2.10
2821  */
2822 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2823  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8, class BoundArg9,
2824  class BoundArg10, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6,
2825  class Arg7, class Arg8, class Arg9, class Arg10, class... FreeArgs>
2826 CallbackArg<FreeArgs...>* make_ref(const T& t,
2827  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2828  BoundArg4, BoundArg5, BoundArg6,
2829  BoundArg7, BoundArg8, BoundArg9,
2830  BoundArg10, FreeArgs...) const,
2831  Arg1&& arg1,
2832  Arg2&& arg2,
2833  Arg3&& arg3,
2834  Arg4&& arg4,
2835  Arg5&& arg5,
2836  Arg6&& arg6,
2837  Arg7&& arg7,
2838  Arg8&& arg8,
2839  Arg9&& arg9,
2840  Arg10&& arg10) {
2841  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2842  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
2843  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
2844  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
2845  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
2846  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
2847  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
2848  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type,
2849  typename std::remove_const<typename std::remove_reference<BoundArg9>::type>::type,
2850  typename std::remove_const<typename std::remove_reference<BoundArg10>::type>::type> Tuple;
2851  return new Callback_memfun_tuple<const T, decltype(func), Tuple, FreeArgs...>
2852  {t, func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
2853  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
2854  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8), std::forward<Arg9>(arg9),
2855  std::forward<Arg10>(arg10)};
2856 }
2857 
2858 /* for static class methods and non-class functions */
2859 
2860 /**
2861  * A convenience function to make Callback::CallbackArg objects
2862  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2863  * is exhausted and the system throws in that case. This exception
2864  * will not be thrown if the library has been installed using the
2865  * \--with-glib-memory-slices-no-compat configuration option (instead
2866  * glib will terminate the program if it is unable to obtain memory
2867  * from the operating system).
2868  */
2869 template <class... FreeArgs>
2870 CallbackArg<FreeArgs...>* make(void (*func)(FreeArgs...)) {
2871  return new Callback_lambda<decltype(func), FreeArgs...>{func};
2872 }
2873 
2874 /**
2875  * Since this function constructs a callback which does not take a
2876  * bound argument, it is a synonym for make() (the two are identical).
2877  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2878  * is exhausted and the system throws in that case. This exception
2879  * will not be thrown if the library has been installed using the
2880  * \--with-glib-memory-slices-no-compat configuration option (instead
2881  * glib will terminate the program if it is unable to obtain memory
2882  * from the operating system).
2883  *
2884  * Since 2.0.0-rc3
2885  */
2886 template <class... FreeArgs>
2887 CallbackArg<FreeArgs...>* make_ref(void (*func)(FreeArgs...)) {
2888  return new Callback_lambda<decltype(func), FreeArgs...>{func};
2889 }
2890 
2891 /**
2892  * A convenience function to make Callback::CallbackArg objects
2893  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2894  * is exhausted and the system throws in that case (this exception
2895  * will not be thrown if the library has been installed using the
2896  * \--with-glib-memory-slices-no-compat configuration option: instead
2897  * glib will terminate the program if it is unable to obtain memory
2898  * from the operating system). It will also throw if the copy
2899  * constructor of a bound argument throws and it is not a reference
2900  * argument.
2901  */
2902 template <class BoundArg, class... FreeArgs>
2903 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg, FreeArgs...),
2904  BoundArg arg) {
2905  typedef std::tuple<BoundArg> Tuple;
2906  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
2907  {func, arg};
2908 }
2909 
2910 /**
2911  * An alternative function to make Callback::CallbackArg objects,
2912  * which is for use where a target function either receives a class
2913  * type bound argument by value, or receives a bound argument by
2914  * reference to const in a case where the generated CallbackArg object
2915  * is to store a copy of that argument instead of just keeping a
2916  * reference.
2917  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2918  * is exhausted and the system throws in that case (this exception
2919  * will not be thrown if the library has been installed using the
2920  * \--with-glib-memory-slices-no-compat configuration option: instead
2921  * glib will terminate the program if it is unable to obtain memory
2922  * from the operating system). It will also throw if the copy or move
2923  * constructor of a bound argument throws.
2924  *
2925  * Since 2.0.0-rc3
2926  */
2927 template <class BoundArg, class Arg, class... FreeArgs>
2928 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg, FreeArgs...),
2929  Arg&& arg) {
2930  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg>::type>::type> Tuple;
2931  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
2932  {func, std::forward<Arg>(arg)};
2933 }
2934 
2935 /**
2936  * A convenience function to make Callback::CallbackArg objects
2937  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2938  * is exhausted and the system throws in that case (this exception
2939  * will not be thrown if the library has been installed using the
2940  * \--with-glib-memory-slices-no-compat configuration option: instead
2941  * glib will terminate the program if it is unable to obtain memory
2942  * from the operating system). It will also throw if the copy
2943  * constructor of a bound argument throws and it is not a reference
2944  * argument.
2945  */
2946 template <class BoundArg1, class BoundArg2, class... FreeArgs>
2947 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2948  BoundArg1 arg1,
2949  BoundArg2 arg2) {
2950  typedef std::tuple<BoundArg1, BoundArg2> Tuple;
2951  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
2952  {func, arg1, arg2};
2953 }
2954 
2955 /**
2956  * An alternative function to make Callback::CallbackArg objects,
2957  * which is for use where a target function either receives a class
2958  * type bound argument by value, or receives a bound argument by
2959  * reference to const in a case where the generated CallbackArg object
2960  * is to store a copy of that argument instead of just keeping a
2961  * reference.
2962  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2963  * is exhausted and the system throws in that case (this exception
2964  * will not be thrown if the library has been installed using the
2965  * \--with-glib-memory-slices-no-compat configuration option: instead
2966  * glib will terminate the program if it is unable to obtain memory
2967  * from the operating system). It will also throw if the copy or move
2968  * constructor of a bound argument throws.
2969  *
2970  * Since 2.0.0-rc3
2971  */
2972 template <class BoundArg1, class BoundArg2, class Arg1, class Arg2, class... FreeArgs>
2973 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2974  Arg1&& arg1,
2975  Arg2&& arg2) {
2976  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
2977  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type> Tuple;
2978  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
2979  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2)};
2980 }
2981 
2982 /**
2983  * A convenience function to make Callback::CallbackArg objects
2984  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2985  * is exhausted and the system throws in that case (this exception
2986  * will not be thrown if the library has been installed using the
2987  * \--with-glib-memory-slices-no-compat configuration option: instead
2988  * glib will terminate the program if it is unable to obtain memory
2989  * from the operating system). It will also throw if the copy
2990  * constructor of a bound argument throws and it is not a reference
2991  * argument.
2992  */
2993 template <class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2994 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
2995  BoundArg1 arg1,
2996  BoundArg2 arg2,
2997  BoundArg3 arg3) {
2998  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3> Tuple;
2999  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3000  {func, arg1, arg2, arg3};
3001 }
3002 
3003 /**
3004  * An alternative function to make Callback::CallbackArg objects,
3005  * which is for use where a target function either receives a class
3006  * type bound argument by value, or receives a bound argument by
3007  * reference to const in a case where the generated CallbackArg object
3008  * is to store a copy of that argument instead of just keeping a
3009  * reference.
3010  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3011  * is exhausted and the system throws in that case (this exception
3012  * will not be thrown if the library has been installed using the
3013  * \--with-glib-memory-slices-no-compat configuration option: instead
3014  * glib will terminate the program if it is unable to obtain memory
3015  * from the operating system). It will also throw if the copy or move
3016  * constructor of a bound argument throws.
3017  *
3018  * Since 2.0.0-rc3
3019  */
3020 template <class BoundArg1, class BoundArg2, class BoundArg3,
3021  class Arg1, class Arg2, class Arg3, class... FreeArgs>
3022 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
3023  Arg1&& arg1,
3024  Arg2&& arg2,
3025  Arg3&& arg3) {
3026  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3027  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3028  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type> Tuple;
3029  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3030  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3)};
3031 }
3032 
3033 /**
3034  * A convenience function to make Callback::CallbackArg objects
3035  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3036  * is exhausted and the system throws in that case (this exception
3037  * will not be thrown if the library has been installed using the
3038  * \--with-glib-memory-slices-no-compat configuration option: instead
3039  * glib will terminate the program if it is unable to obtain memory
3040  * from the operating system). It will also throw if the copy
3041  * constructor of a bound argument throws and it is not a reference
3042  * argument.
3043  */
3044 template <class BoundArg1, class BoundArg2, class BoundArg3,
3045  class BoundArg4, class... FreeArgs>
3046 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3047  BoundArg4, FreeArgs...),
3048  BoundArg1 arg1,
3049  BoundArg2 arg2,
3050  BoundArg3 arg3,
3051  BoundArg4 arg4) {
3052  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4> Tuple;
3053  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3054  {func, arg1, arg2, arg3, arg4};
3055 }
3056 
3057 /**
3058  * An alternative function to make Callback::CallbackArg objects,
3059  * which is for use where a target function either receives a class
3060  * type bound argument by value, or receives a bound argument by
3061  * reference to const in a case where the generated CallbackArg object
3062  * is to store a copy of that argument instead of just keeping a
3063  * reference.
3064  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3065  * is exhausted and the system throws in that case (this exception
3066  * will not be thrown if the library has been installed using the
3067  * \--with-glib-memory-slices-no-compat configuration option: instead
3068  * glib will terminate the program if it is unable to obtain memory
3069  * from the operating system). It will also throw if the copy or move
3070  * constructor of a bound argument throws.
3071  *
3072  * Since 2.0.0-rc3
3073  */
3074 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3075  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
3076 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3077  BoundArg4, FreeArgs...),
3078  Arg1&& arg1,
3079  Arg2&& arg2,
3080  Arg3&& arg3,
3081  Arg4&& arg4) {
3082  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3083  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3084  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
3085  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type> Tuple;
3086  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3087  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2),
3088  std::forward<Arg3>(arg3), std::forward<Arg4>(arg4)};
3089 }
3090 
3091 /**
3092  * A convenience function to make Callback::CallbackArg objects
3093  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3094  * is exhausted and the system throws in that case (this exception
3095  * will not be thrown if the library has been installed using the
3096  * \--with-glib-memory-slices-no-compat configuration option: instead
3097  * glib will terminate the program if it is unable to obtain memory
3098  * from the operating system). It will also throw if the copy
3099  * constructor of a bound argument throws and it is not a reference
3100  * argument.
3101  */
3102 template <class BoundArg1, class BoundArg2, class BoundArg3,
3103  class BoundArg4, class BoundArg5, class... FreeArgs>
3104 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3105  BoundArg4, BoundArg5, FreeArgs...),
3106  BoundArg1 arg1,
3107  BoundArg2 arg2,
3108  BoundArg3 arg3,
3109  BoundArg4 arg4,
3110  BoundArg5 arg5) {
3111  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5> Tuple;
3112  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3113  {func, arg1, arg2, arg3, arg4, arg5};
3114 }
3115 
3116 /**
3117  * An alternative function to make Callback::CallbackArg objects,
3118  * which is for use where a target function either receives a class
3119  * type bound argument by value, or receives a bound argument by
3120  * reference to const in a case where the generated CallbackArg object
3121  * is to store a copy of that argument instead of just keeping a
3122  * reference.
3123  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3124  * is exhausted and the system throws in that case (this exception
3125  * will not be thrown if the library has been installed using the
3126  * \--with-glib-memory-slices-no-compat configuration option: instead
3127  * glib will terminate the program if it is unable to obtain memory
3128  * from the operating system). It will also throw if the copy or move
3129  * constructor of a bound argument throws.
3130  *
3131  * Since 2.0.0-rc3
3132  */
3133 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
3134  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
3135 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3136  BoundArg4, BoundArg5, FreeArgs...),
3137  Arg1&& arg1,
3138  Arg2&& arg2,
3139  Arg3&& arg3,
3140  Arg4&& arg4,
3141  Arg5&& arg5) {
3142  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3143  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3144  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
3145  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
3146  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type> Tuple;
3147  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3148  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
3149  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5)};
3150 }
3151 
3152 /**
3153  * A convenience function to make Callback::CallbackArg objects
3154  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3155  * is exhausted and the system throws in that case (this exception
3156  * will not be thrown if the library has been installed using the
3157  * \--with-glib-memory-slices-no-compat configuration option: instead
3158  * glib will terminate the program if it is unable to obtain memory
3159  * from the operating system). It will also throw if the copy
3160  * constructor of a bound argument throws and it is not a reference
3161  * argument.
3162  * @note More than 5 bound values may not be passed to this function
3163  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3164  * >= 3.4, or (ii) the library is compiled by another compiler with
3165  * appropriate support for C++11 tuples using the \--with-tuple
3166  * configuration option.
3167  *
3168  * Since 2.2.10
3169  */
3170 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3171  class BoundArg5, class BoundArg6, class... FreeArgs>
3172 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3173  BoundArg4, BoundArg5, BoundArg6,
3174  FreeArgs...),
3175  BoundArg1 arg1,
3176  BoundArg2 arg2,
3177  BoundArg3 arg3,
3178  BoundArg4 arg4,
3179  BoundArg5 arg5,
3180  BoundArg6 arg6) {
3181  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
3182  BoundArg5, BoundArg6> Tuple;
3183  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3184  {func, arg1, arg2, arg3, arg4, arg5, arg6};
3185 }
3186 
3187 /**
3188  * An alternative function to make Callback::CallbackArg objects,
3189  * which is for use where a target function either receives a class
3190  * type bound argument by value, or receives a bound argument by
3191  * reference to const in a case where the generated CallbackArg object
3192  * is to store a copy of that argument instead of just keeping a
3193  * reference.
3194  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3195  * is exhausted and the system throws in that case (this exception
3196  * will not be thrown if the library has been installed using the
3197  * \--with-glib-memory-slices-no-compat configuration option: instead
3198  * glib will terminate the program if it is unable to obtain memory
3199  * from the operating system). It will also throw if the copy or move
3200  * constructor of a bound argument throws.
3201  * @note More than 5 bound values may not be passed to this function
3202  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3203  * >= 3.4, or (ii) the library is compiled by another compiler with
3204  * appropriate support for C++11 tuples using the \--with-tuple
3205  * configuration option.
3206  *
3207  * Since 2.2.10
3208  */
3209 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
3210  class BoundArg6, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5,
3211  class Arg6, class... FreeArgs>
3212 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3213  BoundArg4, BoundArg5, BoundArg6,
3214  FreeArgs...),
3215  Arg1&& arg1,
3216  Arg2&& arg2,
3217  Arg3&& arg3,
3218  Arg4&& arg4,
3219  Arg5&& arg5,
3220  Arg6&& arg6) {
3221  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3222  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3223  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
3224  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
3225  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
3226  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type> Tuple;
3227  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3228  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
3229  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6)};
3230 }
3231 
3232 /**
3233  * A convenience function to make Callback::CallbackArg objects
3234  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3235  * is exhausted and the system throws in that case (this exception
3236  * will not be thrown if the library has been installed using the
3237  * \--with-glib-memory-slices-no-compat configuration option: instead
3238  * glib will terminate the program if it is unable to obtain memory
3239  * from the operating system). It will also throw if the copy
3240  * constructor of a bound argument throws and it is not a reference
3241  * argument.
3242  * @note More than 5 bound values may not be passed to this function
3243  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3244  * >= 3.4, or (ii) the library is compiled by another compiler with
3245  * appropriate support for C++11 tuples using the \--with-tuple
3246  * configuration option.
3247  *
3248  * Since 2.2.10
3249  */
3250 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3251  class BoundArg5, class BoundArg6, class BoundArg7, class... FreeArgs>
3252 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3253  BoundArg4, BoundArg5, BoundArg6,
3254  BoundArg7, FreeArgs...),
3255  BoundArg1 arg1,
3256  BoundArg2 arg2,
3257  BoundArg3 arg3,
3258  BoundArg4 arg4,
3259  BoundArg5 arg5,
3260  BoundArg6 arg6,
3261  BoundArg7 arg7) {
3262  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
3263  BoundArg5, BoundArg6, BoundArg7> Tuple;
3264  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3265  {func, arg1, arg2, arg3, arg4, arg5, arg6, arg7};
3266 }
3267 
3268 /**
3269  * An alternative function to make Callback::CallbackArg objects,
3270  * which is for use where a target function either receives a class
3271  * type bound argument by value, or receives a bound argument by
3272  * reference to const in a case where the generated CallbackArg object
3273  * is to store a copy of that argument instead of just keeping a
3274  * reference.
3275  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3276  * is exhausted and the system throws in that case (this exception
3277  * will not be thrown if the library has been installed using the
3278  * \--with-glib-memory-slices-no-compat configuration option: instead
3279  * glib will terminate the program if it is unable to obtain memory
3280  * from the operating system). It will also throw if the copy or move
3281  * constructor of a bound argument throws.
3282  * @note More than 5 bound values may not be passed to this function
3283  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3284  * >= 3.4, or (ii) the library is compiled by another compiler with
3285  * appropriate support for C++11 tuples using the \--with-tuple
3286  * configuration option.
3287  *
3288  * Since 2.2.10
3289  */
3290 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3291  class BoundArg5, class BoundArg6, class BoundArg7, class Arg1, class Arg2,
3292  class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class... FreeArgs>
3293 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3294  BoundArg4, BoundArg5, BoundArg6,
3295  BoundArg7, FreeArgs...),
3296  Arg1&& arg1,
3297  Arg2&& arg2,
3298  Arg3&& arg3,
3299  Arg4&& arg4,
3300  Arg5&& arg5,
3301  Arg6&& arg6,
3302  Arg7&& arg7) {
3303  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3304  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3305  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
3306  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
3307  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
3308  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
3309  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type> Tuple;
3310  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3311  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
3312  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
3313  std::forward<Arg7>(arg7)};
3314 }
3315 
3316 /**
3317  * A convenience function to make Callback::CallbackArg objects
3318  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3319  * is exhausted and the system throws in that case (this exception
3320  * will not be thrown if the library has been installed using the
3321  * \--with-glib-memory-slices-no-compat configuration option: instead
3322  * glib will terminate the program if it is unable to obtain memory
3323  * from the operating system). It will also throw if the copy
3324  * constructor of a bound argument throws and it is not a reference
3325  * argument.
3326  * @note More than 5 bound values may not be passed to this function
3327  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3328  * >= 3.4, or (ii) the library is compiled by another compiler with
3329  * appropriate support for C++11 tuples using the \--with-tuple
3330  * configuration option.
3331  *
3332  * Since 2.2.10
3333  */
3334 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3335  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8,
3336  class... FreeArgs>
3337 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3338  BoundArg4, BoundArg5, BoundArg6,
3339  BoundArg7, BoundArg8, FreeArgs...),
3340  BoundArg1 arg1,
3341  BoundArg2 arg2,
3342  BoundArg3 arg3,
3343  BoundArg4 arg4,
3344  BoundArg5 arg5,
3345  BoundArg6 arg6,
3346  BoundArg7 arg7,
3347  BoundArg8 arg8) {
3348  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
3349  BoundArg5, BoundArg6, BoundArg7, BoundArg8> Tuple;
3350  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3351  {func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8};
3352 }
3353 
3354 /**
3355  * An alternative function to make Callback::CallbackArg objects,
3356  * which is for use where a target function either receives a class
3357  * type bound argument by value, or receives a bound argument by
3358  * reference to const in a case where the generated CallbackArg object
3359  * is to store a copy of that argument instead of just keeping a
3360  * reference.
3361  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3362  * is exhausted and the system throws in that case (this exception
3363  * will not be thrown if the library has been installed using the
3364  * \--with-glib-memory-slices-no-compat configuration option: instead
3365  * glib will terminate the program if it is unable to obtain memory
3366  * from the operating system). It will also throw if the copy or move
3367  * constructor of a bound argument throws.
3368  * @note More than 5 bound values may not be passed to this function
3369  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3370  * >= 3.4, or (ii) the library is compiled by another compiler with
3371  * appropriate support for C++11 tuples using the \--with-tuple
3372  * configuration option.
3373  *
3374  * Since 2.2.10
3375  */
3376 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3377  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8,
3378  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6,
3379  class Arg7, class Arg8, class... FreeArgs>
3380 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3381  BoundArg4, BoundArg5, BoundArg6,
3382  BoundArg7, BoundArg8, FreeArgs...),
3383  Arg1&& arg1,
3384  Arg2&& arg2,
3385  Arg3&& arg3,
3386  Arg4&& arg4,
3387  Arg5&& arg5,
3388  Arg6&& arg6,
3389  Arg7&& arg7,
3390  Arg8&& arg8) {
3391  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3392  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3393  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
3394  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
3395  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
3396  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
3397  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
3398  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type> Tuple;
3399  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3400  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
3401  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
3402  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8)};
3403 }
3404 
3405 /**
3406  * A convenience function to make Callback::CallbackArg objects
3407  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3408  * is exhausted and the system throws in that case (this exception
3409  * will not be thrown if the library has been installed using the
3410  * \--with-glib-memory-slices-no-compat configuration option: instead
3411  * glib will terminate the program if it is unable to obtain memory
3412  * from the operating system). It will also throw if the copy
3413  * constructor of a bound argument throws and it is not a reference
3414  * argument.
3415  * @note More than 5 bound values may not be passed to this function
3416  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3417  * >= 3.4, or (ii) the library is compiled by another compiler with
3418  * appropriate support for C++11 tuples using the \--with-tuple
3419  * configuration option.
3420  *
3421  * Since 2.2.10
3422  */
3423 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3424  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8,
3425  class BoundArg9, class... FreeArgs>
3426 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3427  BoundArg4, BoundArg5, BoundArg6,
3428  BoundArg7, BoundArg8, BoundArg9,
3429  FreeArgs...),
3430  BoundArg1 arg1,
3431  BoundArg2 arg2,
3432  BoundArg3 arg3,
3433  BoundArg4 arg4,
3434  BoundArg5 arg5,
3435  BoundArg6 arg6,
3436  BoundArg7 arg7,
3437  BoundArg8 arg8,
3438  BoundArg9 arg9) {
3439  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
3440  BoundArg5, BoundArg6, BoundArg7, BoundArg8,
3441  BoundArg9> Tuple;
3442  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3443  {func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9};
3444 }
3445 
3446 /**
3447  * An alternative function to make Callback::CallbackArg objects,
3448  * which is for use where a target function either receives a class
3449  * type bound argument by value, or receives a bound argument by
3450  * reference to const in a case where the generated CallbackArg object
3451  * is to store a copy of that argument instead of just keeping a
3452  * reference.
3453  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3454  * is exhausted and the system throws in that case (this exception
3455  * will not be thrown if the library has been installed using the
3456  * \--with-glib-memory-slices-no-compat configuration option: instead
3457  * glib will terminate the program if it is unable to obtain memory
3458  * from the operating system). It will also throw if the copy or move
3459  * constructor of a bound argument throws.
3460  * @note More than 5 bound values may not be passed to this function
3461  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3462  * >= 3.4, or (ii) the library is compiled by another compiler with
3463  * appropriate support for C++11 tuples using the \--with-tuple
3464  * configuration option.
3465  *
3466  * Since 2.2.10
3467  */
3468 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3469  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8,
3470  class BoundArg9, class Arg1, class Arg2, class Arg3, class Arg4,
3471  class Arg5, class Arg6, class Arg7, class Arg8, class Arg9,
3472  class... FreeArgs>
3473 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3474  BoundArg4, BoundArg5, BoundArg6,
3475  BoundArg7, BoundArg8, BoundArg9,
3476  FreeArgs...),
3477  Arg1&& arg1,
3478  Arg2&& arg2,
3479  Arg3&& arg3,
3480  Arg4&& arg4,
3481  Arg5&& arg5,
3482  Arg6&& arg6,
3483  Arg7&& arg7,
3484  Arg8&& arg8,
3485  Arg9&& arg9) {
3486  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3487  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3488  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
3489  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
3490  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
3491  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
3492  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
3493  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type,
3494  typename std::remove_const<typename std::remove_reference<BoundArg9>::type>::type> Tuple;
3495  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3496  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
3497  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
3498  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8), std::forward<Arg9>(arg9)};
3499 }
3500 
3501 /**
3502  * A convenience function to make Callback::CallbackArg objects
3503  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3504  * is exhausted and the system throws in that case (this exception
3505  * will not be thrown if the library has been installed using the
3506  * \--with-glib-memory-slices-no-compat configuration option: instead
3507  * glib will terminate the program if it is unable to obtain memory
3508  * from the operating system). It will also throw if the copy
3509  * constructor of a bound argument throws and it is not a reference
3510  * argument.
3511  * @note More than 5 bound values may not be passed to this function
3512  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3513  * >= 3.4, or (ii) the library is compiled by another compiler with
3514  * appropriate support for C++11 tuples using the \--with-tuple
3515  * configuration option.
3516  *
3517  * Since 2.2.10
3518  */
3519 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3520  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8,
3521  class BoundArg9, class BoundArg10, class... FreeArgs>
3522 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3523  BoundArg4, BoundArg5, BoundArg6,
3524  BoundArg7, BoundArg8, BoundArg9,
3525  BoundArg10, FreeArgs...),
3526  BoundArg1 arg1,
3527  BoundArg2 arg2,
3528  BoundArg3 arg3,
3529  BoundArg4 arg4,
3530  BoundArg5 arg5,
3531  BoundArg6 arg6,
3532  BoundArg7 arg7,
3533  BoundArg8 arg8,
3534  BoundArg9 arg9,
3535  BoundArg10 arg10) {
3536  typedef std::tuple<BoundArg1, BoundArg2, BoundArg3, BoundArg4,
3537  BoundArg5, BoundArg6, BoundArg7, BoundArg8,
3538  BoundArg9, BoundArg10> Tuple;
3539  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3540  {func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10};
3541 }
3542 
3543 /**
3544  * An alternative function to make Callback::CallbackArg objects,
3545  * which is for use where a target function either receives a class
3546  * type bound argument by value, or receives a bound argument by
3547  * reference to const in a case where the generated CallbackArg object
3548  * is to store a copy of that argument instead of just keeping a
3549  * reference.
3550  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3551  * is exhausted and the system throws in that case (this exception
3552  * will not be thrown if the library has been installed using the
3553  * \--with-glib-memory-slices-no-compat configuration option: instead
3554  * glib will terminate the program if it is unable to obtain memory
3555  * from the operating system). It will also throw if the copy or move
3556  * constructor of a bound argument throws.
3557  * @note More than 5 bound values may not be passed to this function
3558  * unless either (i) this library is compiled with gcc >= 4.8 or clang
3559  * >= 3.4, or (ii) the library is compiled by another compiler with
3560  * appropriate support for C++11 tuples using the \--with-tuple
3561  * configuration option.
3562  *
3563  * Since 2.2.10
3564  */
3565 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
3566  class BoundArg5, class BoundArg6, class BoundArg7, class BoundArg8,
3567  class BoundArg9, class BoundArg10, class Arg1, class Arg2, class Arg3,
3568  class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Arg9,
3569  class Arg10, class... FreeArgs>
3570 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
3571  BoundArg4, BoundArg5, BoundArg6,
3572  BoundArg7, BoundArg8, BoundArg9,
3573  BoundArg10, FreeArgs...),
3574  Arg1&& arg1,
3575  Arg2&& arg2,
3576  Arg3&& arg3,
3577  Arg4&& arg4,
3578  Arg5&& arg5,
3579  Arg6&& arg6,
3580  Arg7&& arg7,
3581  Arg8&& arg8,
3582  Arg9&& arg9,
3583  Arg10&& arg10) {
3584  typedef std::tuple<typename std::remove_const<typename std::remove_reference<BoundArg1>::type>::type,
3585  typename std::remove_const<typename std::remove_reference<BoundArg2>::type>::type,
3586  typename std::remove_const<typename std::remove_reference<BoundArg3>::type>::type,
3587  typename std::remove_const<typename std::remove_reference<BoundArg4>::type>::type,
3588  typename std::remove_const<typename std::remove_reference<BoundArg5>::type>::type,
3589  typename std::remove_const<typename std::remove_reference<BoundArg6>::type>::type,
3590  typename std::remove_const<typename std::remove_reference<BoundArg7>::type>::type,
3591  typename std::remove_const<typename std::remove_reference<BoundArg8>::type>::type,
3592  typename std::remove_const<typename std::remove_reference<BoundArg9>::type>::type,
3593  typename std::remove_const<typename std::remove_reference<BoundArg10>::type>::type> Tuple;
3594  return new Callback_fun_tuple<decltype(func), Tuple, FreeArgs...>
3595  {func, std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3),
3596  std::forward<Arg4>(arg4), std::forward<Arg5>(arg5), std::forward<Arg6>(arg6),
3597  std::forward<Arg7>(arg7), std::forward<Arg8>(arg8), std::forward<Arg9>(arg9),
3598  std::forward<Arg10>(arg10)};
3599 }
3600 
3601 #endif // CGU_USE_TUPLE
3602 
3603 /* for std::function objects */
3604 
3605 /**
3606  * A convenience function to make Callback::CallbackArg objects from
3607  * std::function objects.
3608  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3609  * is exhausted and the system throws in that case (this exception
3610  * will not be thrown if the library has been installed using the
3611  * \--with-glib-memory-slices-no-compat configuration option: instead
3612  * glib will terminate the program if it is unable to obtain memory
3613  * from the operating system). It will also throw if the copy
3614  * constructor of a bound argument throws and it is not a reference
3615  * argument.
3616  */
3617 template <class... FreeArgs>
3618 CallbackArg<FreeArgs...>* make(const std::function<void(FreeArgs...)>& f) {
3619  typedef std::function<void(FreeArgs...)> LType;
3620  return new Callback_lambda<LType, FreeArgs...>{f};
3621 }
3622 
3623 /**
3624  * A convenience function to make Callback::Callback objects from
3625  * std::function objects. Since this function takes no bound argument
3626  * (and bound arguments are bound into the std::function object), it
3627  * is a synonym for make() (the two are identical).
3628  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3629  * is exhausted and the system throws in that case (this exception
3630  * will not be thrown if the library has been installed using the
3631  * \--with-glib-memory-slices-no-compat configuration option: instead
3632  * glib will terminate the program if it is unable to obtain memory
3633  * from the operating system). It will also throw if the copy
3634  * constructor of a bound argument throws and it is not a reference
3635  * argument.
3636  */
3637 template <class... FreeArgs>
3638 CallbackArg<FreeArgs...>* make_ref(const std::function<void(FreeArgs...)>& f) {
3639  typedef std::function<void(FreeArgs...)> LType;
3640  return new Callback_lambda<LType, FreeArgs...>{f};
3641 }
3642 
3643 /**
3644  * A convenience function to make Callback::CallbackArg objects from
3645  * std::function objects.
3646  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3647  * is exhausted and the system throws in that case (this exception
3648  * will not be thrown if the library has been installed using the
3649  * \--with-glib-memory-slices-no-compat configuration option: instead
3650  * glib will terminate the program if it is unable to obtain memory
3651  * from the operating system). It will also throw if the copy
3652  * constructor of a bound argument throws and it is not a reference
3653  * argument.
3654  */
3655 template <class... FreeArgs>
3656 CallbackArg<FreeArgs...>* make(std::function<void(FreeArgs...)>&& f) {
3657  typedef std::function<void(FreeArgs...)> LType;
3658  return new Callback_lambda<LType, FreeArgs...>{std::move(f)};
3659 }
3660 
3661 /**
3662  * A convenience function to make Callback::Callback objects from
3663  * std::function objects. Since this function takes no bound argument
3664  * (and bound arguments are bound into the std::function object), it
3665  * is a synonym for make() (the two are identical).
3666  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3667  * is exhausted and the system throws in that case (this exception
3668  * will not be thrown if the library has been installed using the
3669  * \--with-glib-memory-slices-no-compat configuration option: instead
3670  * glib will terminate the program if it is unable to obtain memory
3671  * from the operating system). It will also throw if the copy or move
3672  * constructor of a bound argument throws and it is not a reference
3673  * argument.
3674  */
3675 template <class... FreeArgs>
3676 CallbackArg<FreeArgs...>* make_ref(std::function<void(FreeArgs...)>&& f) {
3677  typedef std::function<void(FreeArgs...)> LType;
3678  return new Callback_lambda<LType, FreeArgs...>{std::move(f)};
3679 }
3680 
3681 // This helper function to construct Callback_lambda objects could be
3682 // implemented as a further overload of Callback::make(). No best
3683 // match ambiguities would arise, because even when Callback::make()
3684 // is passed a function pointer without bound arguments, the overload
3685 // of Callback::make taking a function pointer (as opposed to a
3686 // generic callable object) would still comprise the best match.
3687 // However, to construct Callback_lambda objects, the unbound
3688 // arguments need to be specified by hand, which doesn't happen with
3689 // Callback::make() (it would only be necessary to specify an explicit
3690 // type where a mutable reference argument is to be bound to the
3691 // callback object). It seems to me to be less confusing to the user
3692 // therefore to have a separate Callback::lambda() helper function.
3693 // However, if you disagree please let me know.
3694 
3695 // template parameter packs do not need to be placed last in the case
3696 // of function templates, as type deduction is available for the last
3697 // parameter: there is in fact no function parameter pack in
3698 // Callback::lambda() (function parameter packs must come last).
3699 /**
3700  * A convenience function to make Callback::CallbackArg objects from
3701  * C++11/14 lambda expressions, or from any other arbitrary callable
3702  * object. The types of the unbound arguments (if any) must be
3703  * explicitly specified as template parameters, as they cannot be
3704  * deduced. From version 2.0.10, this function can be called for
3705  * lambda expressions which are declared mutable (in version 2.0.9,
3706  * this function could only be called for non-mutable lambda
3707  * expressions). From version 2.0.16, this function can be passed
3708  * callable objects which are lvalues as well as rvalues (prior to
3709  * version 2.0.16, it could only be passed callable objects which are
3710  * rvalues).
3711  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3712  * is exhausted and the system throws in that case (this exception
3713  * will not be thrown if the library has been installed using the
3714  * \--with-glib-memory-slices-no-compat configuration option: instead
3715  * glib will terminate the program if it is unable to obtain memory
3716  * from the operating system). It will also throw if the copy or move
3717  * constructor of an object captured by the lambda expression throws.
3718  *
3719  * Since 2.0.9
3720  */
3721 template <class... FreeArgs, class Lambda>
3722 CallbackArg<FreeArgs...>* lambda(Lambda&& l) {
3723  typedef typename std::remove_const<typename std::remove_reference<Lambda>::type>::type LType;
3724  return new Callback_lambda<LType, FreeArgs...>{std::forward<Lambda>(l)};
3725 }
3726 
3727 //////////////////////////// OLD STUFF ////////////////////////////
3728 
3729 /* The rest of the things in this file is old stuff, retained in order
3730  to provide API/ABI compatibility - we do not break code. This is
3731  mainly to support gcc-4.6 and gcc-4.7, which do not adequately
3732  implement C++11 tuples. Selection of the callback backend is done
3733  at configuration time, although a specific implementation can be
3734  chosen with the --with-tuple=yes or --with-tuple=no configuration
3735  options. Both backend implementations are binary compatible
3736  because these callback classes are only exported via the
3737  CallbackArg base class. */
3738 
3739 #ifndef DOXYGEN_PARSING
3740 // These classes are retained (i) for use with make_val(), (ii) to
3741 // cover the (highly unlikely) case of someone who has written code
3742 // which instantiates these directly rather than via make() or
3743 // make_ref(), and (iii) to continue to provide an implementation for
3744 // gcc-4.6 and gcc-4.7 which does not use std::tuple. Because these
3745 // classes are only accessed through the base class virtual function,
3746 // they are not needed for ABI compatibility per se.
3747 template <class T, class... FreeArgs>
3748 class Callback0: public CallbackArg<FreeArgs...> {
3749 public:
3750  typedef void (T::* MemFunc)(FreeArgs...);
3751 private:
3752  T* obj;
3753  MemFunc func;
3754 public:
3755  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3756  (obj->*func)(free_args...);
3757  }
3758  Callback0(T& obj_, MemFunc func_): obj(&obj_), func(func_) {}
3759 };
3760 
3761 template <bool unref, class T, class BoundArg, class... FreeArgs>
3762 class Callback1: public CallbackArg<FreeArgs...> {
3763 public:
3764  typedef void (T::* MemFunc)(BoundArg, FreeArgs...);
3765 private:
3766  T* obj;
3767  MemFunc func;
3769 public:
3770  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3771  (obj->*func)(arg, free_args...);
3772  }
3773  template <class Arg>
3774  Callback1(T& obj_, MemFunc func_,
3775  Arg&& arg_): obj(&obj_), func(func_), arg(std::forward<Arg>(arg_)) {}
3776 };
3777 
3778 template <bool unref, class T, class BoundArg1, class BoundArg2, class... FreeArgs>
3779 class Callback2: public CallbackArg<FreeArgs...> {
3780 public:
3781  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...);
3782 private:
3783  T* obj;
3784  MemFunc func;
3787 public:
3788  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3789  (obj->*func)(arg1, arg2, free_args...);
3790  }
3791  template <class Arg1, class Arg2>
3792  Callback2(T& obj_, MemFunc func_,
3793  Arg1&& arg1_,
3794  Arg2&& arg2_): obj(&obj_), func(func_),
3795  arg1(std::forward<Arg1>(arg1_)),
3796  arg2(std::forward<Arg2>(arg2_)) {}
3797 };
3798 
3799 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
3800 class Callback3: public CallbackArg<FreeArgs...> {
3801 public:
3802  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...);
3803 private:
3804  T* obj;
3805  MemFunc func;
3809 public:
3810  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3811  (obj->*func)(arg1, arg2, arg3, free_args...);
3812  }
3813  template <class Arg1, class Arg2, class Arg3>
3814  Callback3(T& obj_, MemFunc func_,
3815  Arg1&& arg1_,
3816  Arg2&& arg2_,
3817  Arg3&& arg3_):
3818  obj(&obj_), func(func_),
3819  arg1(std::forward<Arg1>(arg1_)),
3820  arg2(std::forward<Arg2>(arg2_)),
3821  arg3(std::forward<Arg3>(arg3_)) {}
3822 };
3823 
3824 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
3825  class BoundArg4, class... FreeArgs>
3826 class Callback4: public CallbackArg<FreeArgs...> {
3827 public:
3828  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...);
3829 private:
3830  T* obj;
3831  MemFunc func;
3836 public:
3837  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3838  (obj->*func)(arg1, arg2, arg3, arg4, free_args...);
3839  }
3840  template <class Arg1, class Arg2, class Arg3, class Arg4>
3841  Callback4(T& obj_, MemFunc func_,
3842  Arg1&& arg1_,
3843  Arg2&& arg2_,
3844  Arg3&& arg3_,
3845  Arg4&& arg4_):
3846  obj(&obj_), func(func_),
3847  arg1(std::forward<Arg1>(arg1_)),
3848  arg2(std::forward<Arg2>(arg2_)),
3849  arg3(std::forward<Arg3>(arg3_)),
3850  arg4(std::forward<Arg4>(arg4_)) {}
3851 };
3852 
3853 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
3854  class BoundArg4, class BoundArg5, class... FreeArgs>
3855 class Callback5: public CallbackArg<FreeArgs...> {
3856 public:
3857  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3,
3858  BoundArg4, BoundArg5, FreeArgs...);
3859 private:
3860  T* obj;
3861  MemFunc func;
3867 public:
3868  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3869  (obj->*func)(arg1, arg2, arg3, arg4, arg5, free_args...);
3870  }
3871  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
3872  Callback5(T& obj_, MemFunc func_,
3873  Arg1&& arg1_,
3874  Arg2&& arg2_,
3875  Arg3&& arg3_,
3876  Arg4&& arg4_,
3877  Arg5&& arg5_):
3878  obj(&obj_), func(func_),
3879  arg1(std::forward<Arg1>(arg1_)),
3880  arg2(std::forward<Arg2>(arg2_)),
3881  arg3(std::forward<Arg3>(arg3_)),
3882  arg4(std::forward<Arg4>(arg4_)),
3883  arg5(std::forward<Arg5>(arg5_)) {}
3884 };
3885 
3886 template <class T, class... FreeArgs>
3887 class Callback0_const: public CallbackArg<FreeArgs...> {
3888 public:
3889  typedef void (T::* MemFunc)(FreeArgs...) const;
3890 private:
3891  const T* obj;
3892  MemFunc func;
3893 public:
3894  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3895  (obj->*func)(free_args...);
3896  }
3897  Callback0_const(const T& obj_, MemFunc func_): obj(&obj_), func(func_) {}
3898 };
3899 
3900 template <bool unref, class T, class BoundArg, class... FreeArgs>
3901 class Callback1_const: public CallbackArg<FreeArgs...> {
3902 public:
3903  typedef void (T::* MemFunc)(BoundArg, FreeArgs...) const;
3904 private:
3905  const T* obj;
3906  MemFunc func;
3908 public:
3909  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3910  (obj->*func)(arg, free_args...);
3911  }
3912  template <class Arg>
3913  Callback1_const(const T& obj_, MemFunc func_,
3914  Arg&& arg_): obj(&obj_), func(func_), arg(std::forward<Arg>(arg_)) {}
3915 };
3916 
3917 template <bool unref, class T, class BoundArg1, class BoundArg2, class... FreeArgs>
3918 class Callback2_const: public CallbackArg<FreeArgs...> {
3919 public:
3920  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...) const;
3921 private:
3922  const T* obj;
3923  MemFunc func;
3926 public:
3927  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3928  (obj->*func)(arg1, arg2, free_args...);
3929  }
3930  template <class Arg1, class Arg2>
3931  Callback2_const(const T& obj_, MemFunc func_,
3932  Arg1&& arg1_,
3933  Arg2&& arg2_): obj(&obj_), func(func_),
3934  arg1(std::forward<Arg1>(arg1_)),
3935  arg2(std::forward<Arg2>(arg2_)) {}
3936 };
3937 
3938 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
3939 class Callback3_const: public CallbackArg<FreeArgs...> {
3940 public:
3941  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const;
3942 private:
3943  const T* obj;
3944  MemFunc func;
3948 public:
3949  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3950  (obj->*func)(arg1, arg2, arg3, free_args...);
3951  }
3952  template <class Arg1, class Arg2, class Arg3>
3953  Callback3_const(const T& obj_, MemFunc func_,
3954  Arg1&& arg1_,
3955  Arg2&& arg2_,
3956  Arg3&& arg3_):
3957  obj(&obj_), func(func_),
3958  arg1(std::forward<Arg1>(arg1_)),
3959  arg2(std::forward<Arg2>(arg2_)),
3960  arg3(std::forward<Arg3>(arg3_)) {}
3961 };
3962 
3963 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
3964  class BoundArg4, class... FreeArgs>
3965 class Callback4_const: public CallbackArg<FreeArgs...> {
3966 public:
3967  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...) const;
3968 private:
3969  const T* obj;
3970  MemFunc func;
3975 public:
3976  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
3977  (obj->*func)(arg1, arg2, arg3, arg4, free_args...);
3978  }
3979  template <class Arg1, class Arg2, class Arg3, class Arg4>
3980  Callback4_const(const T& obj_, MemFunc func_,
3981  Arg1&& arg1_,
3982  Arg2&& arg2_,
3983  Arg3&& arg3_,
3984  Arg4&& arg4_):
3985  obj(&obj_), func(func_),
3986  arg1(std::forward<Arg1>(arg1_)),
3987  arg2(std::forward<Arg2>(arg2_)),
3988  arg3(std::forward<Arg3>(arg3_)),
3989  arg4(std::forward<Arg4>(arg4_)) {}
3990 };
3991 
3992 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
3993  class BoundArg4, class BoundArg5, class... FreeArgs>
3994 class Callback5_const: public CallbackArg<FreeArgs...> {
3995 public:
3996  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3,
3997  BoundArg4, BoundArg5, FreeArgs...) const;
3998 private:
3999  const T* obj;
4000  MemFunc func;
4006 public:
4007  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
4008  (obj->*func)(arg1, arg2, arg3, arg4, arg5, free_args...);
4009  }
4010  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
4011  Callback5_const(const T& obj_, MemFunc func_,
4012  Arg1&& arg1_,
4013  Arg2&& arg2_,
4014  Arg3&& arg3_,
4015  Arg4&& arg4_,
4016  Arg5&& arg5_):
4017  obj(&obj_), func(func_),
4018  arg1(std::forward<Arg1>(arg1_)),
4019  arg2(std::forward<Arg2>(arg2_)),
4020  arg3(std::forward<Arg3>(arg3_)),
4021  arg4(std::forward<Arg4>(arg4_)),
4022  arg5(std::forward<Arg5>(arg5_)) {}
4023 };
4024 
4025 template <class... FreeArgs>
4026 class Callback0_static: public CallbackArg<FreeArgs...> {
4027 public:
4028  typedef void (*Func)(FreeArgs...);
4029 private:
4030  Func func;
4031 public:
4032  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
4033  func(free_args...);
4034  }
4035  Callback0_static(Func func_): func(func_) {}
4036 };
4037 
4038 template <bool unref, class BoundArg, class... FreeArgs>
4039 class Callback1_static: public CallbackArg<FreeArgs...> {
4040 public:
4041  typedef void (*Func)(BoundArg, FreeArgs...);
4042 private:
4043  Func func;
4045 public:
4046  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
4047  func(arg, free_args...);
4048  }
4049  template <class Arg>
4050  Callback1_static(Func func_, Arg&& arg_): func(func_), arg(std::forward<Arg>(arg_)) {}
4051 };
4052 
4053 template <bool unref, class BoundArg1, class BoundArg2, class... FreeArgs>
4054 class Callback2_static: public CallbackArg<FreeArgs...> {
4055 public:
4056  typedef void (*Func)(BoundArg1, BoundArg2, FreeArgs...);
4057 private:
4058  Func func;
4061 public:
4062  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
4063  func(arg1, arg2, free_args...);
4064  }
4065  template <class Arg1, class Arg2>
4066  Callback2_static(Func func_, Arg1&& arg1_,
4067  Arg2&& arg2_): func(func_),
4068  arg1(std::forward<Arg1>(arg1_)),
4069  arg2(std::forward<Arg2>(arg2_)) {}
4070 };
4071 
4072 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
4073 class Callback3_static: public CallbackArg<FreeArgs...> {
4074 public:
4075  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...);
4076 private:
4077  Func func;
4081 public:
4082  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
4083  func(arg1, arg2, arg3, free_args...);
4084  }
4085  template <class Arg1, class Arg2, class Arg3>
4086  Callback3_static(Func func_,
4087  Arg1&& arg1_,
4088  Arg2&& arg2_,
4089  Arg3&& arg3_):
4090  func(func_),
4091  arg1(std::forward<Arg1>(arg1_)),
4092  arg2(std::forward<Arg2>(arg2_)),
4093  arg3(std::forward<Arg3>(arg3_)) {}
4094 };
4095 
4096 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3,
4097  class BoundArg4, class... FreeArgs>
4098 class Callback4_static: public CallbackArg<FreeArgs...> {
4099 public:
4100  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...);
4101 private:
4102  Func func;
4107 public:
4108  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
4109  func(arg1, arg2, arg3, arg4, free_args...);
4110  }
4111  template <class Arg1, class Arg2, class Arg3, class Arg4>
4112  Callback4_static(Func func_,
4113  Arg1&& arg1_,
4114  Arg2&& arg2_,
4115  Arg3&& arg3_,
4116  Arg4&& arg4_):
4117  func(func_),
4118  arg1(std::forward<Arg1>(arg1_)),
4119  arg2(std::forward<Arg2>(arg2_)),
4120  arg3(std::forward<Arg3>(arg3_)),
4121  arg4(std::forward<Arg4>(arg4_)) {}
4122 };
4123 
4124 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3,
4125  class BoundArg4, class BoundArg5, class... FreeArgs>
4126 class Callback5_static: public CallbackArg<FreeArgs...> {
4127 public:
4128  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3,
4129  BoundArg4, BoundArg5, FreeArgs...);
4130 private:
4131  Func func;
4137 public:
4138  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
4139  func(arg1, arg2, arg3, arg4, arg5, free_args...);
4140  }
4141  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
4142  Callback5_static(Func func_,
4143  Arg1&& arg1_,
4144  Arg2&& arg2_,
4145  Arg3&& arg3_,
4146  Arg4&& arg4_,
4147  Arg5&& arg5_):
4148  func(func_),
4149  arg1(std::forward<Arg1>(arg1_)),
4150  arg2(std::forward<Arg2>(arg2_)),
4151  arg3(std::forward<Arg3>(arg3_)),
4152  arg4(std::forward<Arg4>(arg4_)),
4153  arg5(std::forward<Arg5>(arg5_)) {}
4154 };
4155 
4156 /*
4157  * DEPRECATED. These make_val() functions are retained for API
4158  * compatibility only, but should not be used in new code and are not
4159  * documented. Use make_ref() instead.
4160  */
4161 template <class T, class... FreeArgs>
4162 CallbackArg<FreeArgs...>* make_val(T& t,
4163  void (T::*func)(FreeArgs...)) {
4164  return new Callback0<T, FreeArgs...>{t, func};
4165 }
4166 template <class T, class BoundArg, class... FreeArgs>
4167 CallbackArg<FreeArgs...>* make_val(T& t,
4168  void (T::*func)(BoundArg, FreeArgs...),
4169  const BoundArg& arg) {
4170  return new Callback1<false, T, BoundArg, FreeArgs...>{t, func, arg};
4171 }
4172 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
4173 CallbackArg<FreeArgs...>* make_val(T& t,
4174  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
4175  const BoundArg1& arg1,
4176  const BoundArg2& arg2) {
4177  return new Callback2<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
4178 }
4179 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
4180 CallbackArg<FreeArgs...>* make_val(T& t,
4181  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
4182  const BoundArg1& arg1,
4183  const BoundArg2& arg2,
4184  const BoundArg3& arg3) {
4185  return new Callback3<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
4186 }
4187 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4188  class BoundArg4, class... FreeArgs>
4189 CallbackArg<FreeArgs...>* make_val(T& t,
4190  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4191  BoundArg4, FreeArgs...),
4192  const BoundArg1& arg1,
4193  const BoundArg2& arg2,
4194  const BoundArg3& arg3,
4195  const BoundArg4& arg4) {
4196  return new Callback4<false, T, BoundArg1, BoundArg2, BoundArg3,
4197  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
4198 }
4199 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4200  class BoundArg4, class BoundArg5, class... FreeArgs>
4201 CallbackArg<FreeArgs...>* make_val(T& t,
4202  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4203  BoundArg4, BoundArg5, FreeArgs...),
4204  const BoundArg1& arg1,
4205  const BoundArg2& arg2,
4206  const BoundArg3& arg3,
4207  const BoundArg4& arg4,
4208  const BoundArg5& arg5) {
4209  return new Callback5<false, T, BoundArg1, BoundArg2, BoundArg3,
4210  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
4211 }
4212 template <class T, class... FreeArgs>
4213 CallbackArg<FreeArgs...>* make_val(const T& t,
4214  void (T::*func)(FreeArgs...) const) {
4215  return new Callback0_const<T, FreeArgs...>{t, func};
4216 }
4217 template <class T, class BoundArg, class... FreeArgs>
4218 CallbackArg<FreeArgs...>* make_val(const T& t,
4219  void (T::*func)(BoundArg, FreeArgs...) const,
4220  const BoundArg& arg) {
4221  return new Callback1_const<false, T, BoundArg, FreeArgs...>{t, func, arg};
4222 }
4223 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
4224 CallbackArg<FreeArgs...>* make_val(const T& t,
4225  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
4226  const BoundArg1& arg1,
4227  const BoundArg2& arg2) {
4228  return new Callback2_const<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
4229 }
4230 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
4231 CallbackArg<FreeArgs...>* make_val(const T& t,
4232  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
4233  const BoundArg1& arg1,
4234  const BoundArg2& arg2,
4235  const BoundArg3& arg3) {
4236  return new Callback3_const<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
4237 }
4238 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4239  class BoundArg4, class... FreeArgs>
4240 CallbackArg<FreeArgs...>* make_val(const T& t,
4241  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4242  BoundArg4, FreeArgs...) const,
4243  const BoundArg1& arg1,
4244  const BoundArg2& arg2,
4245  const BoundArg3& arg3,
4246  const BoundArg4& arg4) {
4247  return new Callback4_const<false, T, BoundArg1, BoundArg2, BoundArg3,
4248  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
4249 }
4250 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4251  class BoundArg4, class BoundArg5, class... FreeArgs>
4252 CallbackArg<FreeArgs...>* make_val(const T& t,
4253  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4254  BoundArg4, BoundArg5, FreeArgs...) const,
4255  const BoundArg1& arg1,
4256  const BoundArg2& arg2,
4257  const BoundArg3& arg3,
4258  const BoundArg4& arg4,
4259  const BoundArg5& arg5) {
4260  return new Callback5_const<false, T, BoundArg1, BoundArg2, BoundArg3,
4261  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
4262 }
4263 template <class... FreeArgs>
4264 CallbackArg<FreeArgs...>* make_val(void (*func)(FreeArgs...)) {
4265  return new Callback0_static<FreeArgs...>{func};
4266 }
4267 template <class BoundArg, class... FreeArgs>
4268 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg, FreeArgs...),
4269  const BoundArg& arg) {
4270  return new Callback1_static<false, BoundArg, FreeArgs...>{func, arg};
4271 }
4272 template <class BoundArg1, class BoundArg2, class... FreeArgs>
4273 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
4274  const BoundArg1& arg1,
4275  const BoundArg2& arg2) {
4276  return new Callback2_static<false, BoundArg1, BoundArg2, FreeArgs...>{func, arg1, arg2};
4277 }
4278 template <class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
4279 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
4280  const BoundArg1& arg1,
4281  const BoundArg2& arg2,
4282  const BoundArg3& arg3) {
4283  return new Callback3_static<false, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func, arg1, arg2, arg3};
4284 }
4285 template <class BoundArg1, class BoundArg2, class BoundArg3,
4286  class BoundArg4, class... FreeArgs>
4287 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3,
4288  BoundArg4, FreeArgs...),
4289  const BoundArg1& arg1,
4290  const BoundArg2& arg2,
4291  const BoundArg3& arg3,
4292  const BoundArg4& arg4) {
4293  return new Callback4_static<false, BoundArg1, BoundArg2, BoundArg3,
4294  BoundArg4, FreeArgs...>{func, arg1, arg2, arg3, arg4};
4295 }
4296 template <class BoundArg1, class BoundArg2, class BoundArg3,
4297  class BoundArg4, class BoundArg5, class... FreeArgs>
4298 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3,
4299  BoundArg4, BoundArg5, FreeArgs...),
4300  const BoundArg1& arg1,
4301  const BoundArg2& arg2,
4302  const BoundArg3& arg3,
4303  const BoundArg4& arg4,
4304  const BoundArg5& arg5) {
4305  return new Callback5_static<false, BoundArg1, BoundArg2, BoundArg3,
4306  BoundArg4, BoundArg5, FreeArgs...>{func, arg1, arg2, arg3, arg4, arg5};
4307 }
4308 template <class... FreeArgs>
4309 CallbackArg<FreeArgs...>* make_val(const std::function<void(FreeArgs...)>& f) {
4310  typedef std::function<void(FreeArgs...)> LType;
4311  return new Callback_lambda<LType, FreeArgs...>{f};
4312 }
4313 template <class... FreeArgs>
4314 CallbackArg<FreeArgs...>* make_val(std::function<void(FreeArgs...)>&& f) {
4315  typedef std::function<void(FreeArgs...)> LType;
4316  return new Callback_lambda<LType, FreeArgs...>{std::move(f)};
4317 }
4318 
4319 #ifndef CGU_USE_TUPLE
4320 
4321 template <class T, class... FreeArgs>
4322 CallbackArg<FreeArgs...>* make(T& t,
4323  void (T::*func)(FreeArgs...)) {
4324  return new Callback0<T, FreeArgs...>{t, func};
4325 }
4326 
4327 template <class T, class... FreeArgs>
4328 CallbackArg<FreeArgs...>* make_ref(T& t,
4329  void (T::*func)(FreeArgs...)) {
4330  return new Callback0<T, FreeArgs...>{t, func};
4331 }
4332 
4333 template <class T, class BoundArg, class... FreeArgs>
4334 CallbackArg<FreeArgs...>* make(T& t,
4335  void (T::*func)(BoundArg, FreeArgs...),
4336  BoundArg arg) {
4337  return new Callback1<false, T, BoundArg, FreeArgs...>{t, func, arg};
4338 }
4339 
4340 template <class T, class BoundArg, class Arg, class... FreeArgs>
4341 CallbackArg<FreeArgs...>* make_ref(T& t,
4342  void (T::*func)(BoundArg, FreeArgs...),
4343  Arg&& arg) {
4344  return new Callback1<true, T, BoundArg, FreeArgs...>{t, func, std::forward<Arg>(arg)};
4345 }
4346 
4347 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
4348 CallbackArg<FreeArgs...>* make(T& t,
4349  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
4350  BoundArg1 arg1,
4351  BoundArg2 arg2) {
4352  return new Callback2<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
4353 }
4354 
4355 template <class T, class BoundArg1, class BoundArg2,
4356  class Arg1, class Arg2, class... FreeArgs>
4357 CallbackArg<FreeArgs...>* make_ref(T& t,
4358  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
4359  Arg1&& arg1,
4360  Arg2&& arg2) {
4361  return new Callback2<true, T, BoundArg1, BoundArg2, FreeArgs...>{t, func,
4362  std::forward<Arg1>(arg1),
4363  std::forward<Arg2>(arg2)};
4364 }
4365 
4366 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
4367 CallbackArg<FreeArgs...>* make(T& t,
4368  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
4369  BoundArg1 arg1,
4370  BoundArg2 arg2,
4371  BoundArg3 arg3) {
4372  return new Callback3<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
4373 }
4374 
4375 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4376  class Arg1, class Arg2, class Arg3, class... FreeArgs>
4377 CallbackArg<FreeArgs...>* make_ref(T& t,
4378  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
4379  Arg1&& arg1,
4380  Arg2&& arg2,
4381  Arg3&& arg3) {
4382  return new Callback3<true, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func,
4383  std::forward<Arg1>(arg1),
4384  std::forward<Arg2>(arg2),
4385  std::forward<Arg3>(arg3)};
4386 }
4387 
4388 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4389  class BoundArg4, class... FreeArgs>
4390 CallbackArg<FreeArgs...>* make(T& t,
4391  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4392  BoundArg4, FreeArgs...),
4393  BoundArg1 arg1,
4394  BoundArg2 arg2,
4395  BoundArg3 arg3,
4396  BoundArg4 arg4) {
4397  return new Callback4<false, T, BoundArg1, BoundArg2, BoundArg3,
4398  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
4399 }
4400 
4401 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
4402  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
4403 CallbackArg<FreeArgs...>* make_ref(T& t,
4404  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4405  BoundArg4, FreeArgs...),
4406  Arg1&& arg1,
4407  Arg2&& arg2,
4408  Arg3&& arg3,
4409  Arg4&& arg4) {
4410  return new Callback4<true, T, BoundArg1, BoundArg2, BoundArg3,
4411  BoundArg4, FreeArgs...>{t, func,
4412  std::forward<Arg1>(arg1),
4413  std::forward<Arg2>(arg2),
4414  std::forward<Arg3>(arg3),
4415  std::forward<Arg4>(arg4)};
4416 }
4417 
4418 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4419  class BoundArg4, class BoundArg5, class... FreeArgs>
4420 CallbackArg<FreeArgs...>* make(T& t,
4421  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4422  BoundArg4, BoundArg5, FreeArgs...),
4423  BoundArg1 arg1,
4424  BoundArg2 arg2,
4425  BoundArg3 arg3,
4426  BoundArg4 arg4,
4427  BoundArg5 arg5) {
4428  return new Callback5<false, T, BoundArg1, BoundArg2, BoundArg3,
4429  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
4430 }
4431 
4432 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
4433  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
4434 CallbackArg<FreeArgs...>* make_ref(T& t,
4435  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4436  BoundArg4, BoundArg5, FreeArgs...),
4437  Arg1&& arg1,
4438  Arg2&& arg2,
4439  Arg3&& arg3,
4440  Arg4&& arg4,
4441  Arg5&& arg5) {
4442  return new Callback5<true, T, BoundArg1, BoundArg2, BoundArg3,
4443  BoundArg4, BoundArg5, FreeArgs...>{t, func,
4444  std::forward<Arg1>(arg1),
4445  std::forward<Arg2>(arg2),
4446  std::forward<Arg3>(arg3),
4447  std::forward<Arg4>(arg4),
4448  std::forward<Arg5>(arg5)};
4449 }
4450 
4451 template <class T, class... FreeArgs>
4452 CallbackArg<FreeArgs...>* make(const T& t,
4453  void (T::*func)(FreeArgs...) const) {
4454  return new Callback0_const<T, FreeArgs...>{t, func};
4455 }
4456 
4457 template <class T, class... FreeArgs>
4458 CallbackArg<FreeArgs...>* make_ref(const T& t,
4459  void (T::*func)(FreeArgs...) const) {
4460  return new Callback0_const<T, FreeArgs...>{t, func};
4461 }
4462 
4463 template <class T, class BoundArg, class... FreeArgs>
4464 CallbackArg<FreeArgs...>* make(const T& t,
4465  void (T::*func)(BoundArg, FreeArgs...) const,
4466  BoundArg arg) {
4467  return new Callback1_const<false, T, BoundArg, FreeArgs...>{t, func, arg};
4468 }
4469 
4470 template <class T, class BoundArg, class Arg, class... FreeArgs>
4471 CallbackArg<FreeArgs...>* make_ref(const T& t,
4472  void (T::*func)(BoundArg, FreeArgs...) const,
4473  Arg&& arg) {
4474  return new Callback1_const<true, T, BoundArg, FreeArgs...>{t, func, std::forward<Arg>(arg)};
4475 }
4476 
4477 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
4478 CallbackArg<FreeArgs...>* make(const T& t,
4479  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
4480  BoundArg1 arg1,
4481  BoundArg2 arg2) {
4482  return new Callback2_const<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
4483 }
4484 
4485 template <class T, class BoundArg1, class BoundArg2,
4486  class Arg1, class Arg2, class... FreeArgs>
4487 CallbackArg<FreeArgs...>* make_ref(const T& t,
4488  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
4489  Arg1&& arg1,
4490  Arg2&& arg2) {
4491  return new Callback2_const<true, T, BoundArg1, BoundArg2, FreeArgs...>{t, func,
4492  std::forward<Arg1>(arg1),
4493  std::forward<Arg2>(arg2)};
4494 }
4495 
4496 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
4497 CallbackArg<FreeArgs...>* make(const T& t,
4498  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
4499  BoundArg1 arg1,
4500  BoundArg2 arg2,
4501  BoundArg3 arg3) {
4502  return new Callback3_const<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
4503 }
4504 
4505 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4506  class Arg1, class Arg2, class Arg3, class... FreeArgs>
4507 CallbackArg<FreeArgs...>* make_ref(const T& t,
4508  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
4509  Arg1&& arg1,
4510  Arg2&& arg2,
4511  Arg3&& arg3) {
4512  return new Callback3_const<true, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func,
4513  std::forward<Arg1>(arg1),
4514  std::forward<Arg2>(arg2),
4515  std::forward<Arg3>(arg3)};
4516 }
4517 
4518 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4519  class BoundArg4, class... FreeArgs>
4520 CallbackArg<FreeArgs...>* make(const T& t,
4521  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4522  BoundArg4, FreeArgs...) const,
4523  BoundArg1 arg1,
4524  BoundArg2 arg2,
4525  BoundArg3 arg3,
4526  BoundArg4 arg4) {
4527  return new Callback4_const<false, T, BoundArg1, BoundArg2, BoundArg3,
4528  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
4529 }
4530 
4531 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
4532  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
4533 CallbackArg<FreeArgs...>* make_ref(const T& t,
4534  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4535  BoundArg4, FreeArgs...) const,
4536  Arg1&& arg1,
4537  Arg2&& arg2,
4538  Arg3&& arg3,
4539  Arg4&& arg4) {
4540  return new Callback4_const<true, T, BoundArg1, BoundArg2, BoundArg3,
4541  BoundArg4, FreeArgs...>{t, func,
4542  std::forward<Arg1>(arg1),
4543  std::forward<Arg2>(arg2),
4544  std::forward<Arg3>(arg3),
4545  std::forward<Arg4>(arg4)};
4546 }
4547 
4548 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
4549  class BoundArg4, class BoundArg5, class... FreeArgs>
4550 CallbackArg<FreeArgs...>* make(const T& t,
4551  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4552  BoundArg4, BoundArg5, FreeArgs...) const,
4553  BoundArg1 arg1,
4554  BoundArg2 arg2,
4555  BoundArg3 arg3,
4556  BoundArg4 arg4,
4557  BoundArg5 arg5) {
4558  return new Callback5_const<false, T, BoundArg1, BoundArg2, BoundArg3,
4559  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
4560 }
4561 
4562 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
4563  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
4564 CallbackArg<FreeArgs...>* make_ref(const T& t,
4565  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
4566  BoundArg4, BoundArg5, FreeArgs...) const,
4567  Arg1&& arg1,
4568  Arg2&& arg2,
4569  Arg3&& arg3,
4570  Arg4&& arg4,
4571  Arg5&& arg5) {
4572  return new Callback5_const<true, T, BoundArg1, BoundArg2, BoundArg3,
4573  BoundArg4, BoundArg5, FreeArgs...>{t, func,
4574  std::forward<Arg1>(arg1),
4575  std::forward<Arg2>(arg2),
4576  std::forward<Arg3>(arg3),
4577  std::forward<Arg4>(arg4),
4578  std::forward<Arg5>(arg5)};
4579 }
4580 
4581 template <class... FreeArgs>
4582 CallbackArg<FreeArgs...>* make(void (*func)(FreeArgs...)) {
4583  return new Callback0_static<FreeArgs...>{func};
4584 }
4585 
4586 template <class... FreeArgs>
4587 CallbackArg<FreeArgs...>* make_ref(void (*func)(FreeArgs...)) {
4588  return new Callback0_static<FreeArgs...>{func};
4589 }
4590 
4591 template <class BoundArg, class... FreeArgs>
4592 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg, FreeArgs...),
4593  BoundArg arg) {
4594  return new Callback1_static<false, BoundArg, FreeArgs...>{func, arg};
4595 }
4596 
4597 template <class BoundArg, class Arg, class... FreeArgs>
4598 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg, FreeArgs...),
4599  Arg&& arg) {
4600  return new Callback1_static<true, BoundArg, FreeArgs...>{func, std::forward<Arg>(arg)};
4601 }
4602 
4603 template <class BoundArg1, class BoundArg2, class... FreeArgs>
4604 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
4605  BoundArg1 arg1,
4606  BoundArg2 arg2) {
4607  return new Callback2_static<false, BoundArg1, BoundArg2, FreeArgs...>{func, arg1, arg2};
4608 }
4609 
4610 template <class BoundArg1, class BoundArg2, class Arg1, class Arg2, class... FreeArgs>
4611 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
4612  Arg1&& arg1,
4613  Arg2&& arg2) {
4614  return new Callback2_static<true, BoundArg1, BoundArg2, FreeArgs...>{func,
4615  std::forward<Arg1>(arg1),
4616  std::forward<Arg2>(arg2)};
4617 }
4618 
4619 template <class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
4620 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
4621  BoundArg1 arg1,
4622  BoundArg2 arg2,
4623  BoundArg3 arg3) {
4624  return new Callback3_static<false, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func, arg1, arg2, arg3};
4625 }
4626 
4627 template <class BoundArg1, class BoundArg2, class BoundArg3,
4628  class Arg1, class Arg2, class Arg3, class... FreeArgs>
4629 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
4630  Arg1&& arg1,
4631  Arg2&& arg2,
4632  Arg3&& arg3) {
4633  return new Callback3_static<true, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func,
4634  std::forward<Arg1>(arg1),
4635  std::forward<Arg2>(arg2),
4636  std::forward<Arg3>(arg3)};
4637 }
4638 
4639 template <class BoundArg1, class BoundArg2, class BoundArg3,
4640  class BoundArg4, class... FreeArgs>
4641 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
4642  BoundArg4, FreeArgs...),
4643  BoundArg1 arg1,
4644  BoundArg2 arg2,
4645  BoundArg3 arg3,
4646  BoundArg4 arg4) {
4647  return new Callback4_static<false, BoundArg1, BoundArg2, BoundArg3,
4648  BoundArg4, FreeArgs...>{func, arg1, arg2, arg3, arg4};
4649 }
4650 
4651 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
4652  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
4653 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
4654  BoundArg4, FreeArgs...),
4655  Arg1&& arg1,
4656  Arg2&& arg2,
4657  Arg3&& arg3,
4658  Arg4&& arg4) {
4659  return new Callback4_static<true, BoundArg1, BoundArg2, BoundArg3,
4660  BoundArg4, FreeArgs...>{func,
4661  std::forward<Arg1>(arg1),
4662  std::forward<Arg2>(arg2),
4663  std::forward<Arg3>(arg3),
4664  std::forward<Arg4>(arg4)};
4665 }
4666 
4667 template <class BoundArg1, class BoundArg2, class BoundArg3,
4668  class BoundArg4, class BoundArg5, class... FreeArgs>
4669 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
4670  BoundArg4, BoundArg5, FreeArgs...),
4671  BoundArg1 arg1,
4672  BoundArg2 arg2,
4673  BoundArg3 arg3,
4674  BoundArg4 arg4,
4675  BoundArg5 arg5) {
4676  return new Callback5_static<false, BoundArg1, BoundArg2, BoundArg3,
4677  BoundArg4, BoundArg5, FreeArgs...>{func, arg1, arg2, arg3, arg4, arg5};
4678 }
4679 
4680 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
4681  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
4682 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
4683  BoundArg4, BoundArg5, FreeArgs...),
4684  Arg1&& arg1,
4685  Arg2&& arg2,
4686  Arg3&& arg3,
4687  Arg4&& arg4,
4688  Arg5&& arg5) {
4689  return new Callback5_static<true, BoundArg1, BoundArg2, BoundArg3,
4690  BoundArg4, BoundArg5, FreeArgs...>{func,
4691  std::forward<Arg1>(arg1),
4692  std::forward<Arg2>(arg2),
4693  std::forward<Arg3>(arg3),
4694  std::forward<Arg4>(arg4),
4695  std::forward<Arg5>(arg5)};
4696 }
4697 
4698 #endif // CGU_USE_TUPLE
4699 
4700 #endif // DOXYGEN_PARSING
4701 
4702 } // namespace Callback
4703 
4704 class Releaser;
4705 
4706 namespace Callback {
4707 
4708 /**
4709  * Posts a callback for execution by a glib main loop. It is
4710  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
4711  * has been called. glib >= 2.32 does not require g_thread_init() to
4712  * be called. This function will not throw.
4713  * @param cb The callback object. Ownership is taken of this object,
4714  * and it will be deleted when it has been finished with.
4715  * @param priority The priority to be given to the callback in the
4716  * main loop. In ascending order of priorities, priorities are
4717  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
4718  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
4719  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
4720  * callback will appear in the event list in the main loop, not the
4721  * priority which the OS will adopt
4722  * @param context The glib main loop context in which the callback is
4723  * to be executed (the default of NULL will cause the callback to be
4724  * executed in the main program loop, and this is usually what is
4725  * wanted).
4726  * @note 1. Cancellation of the receiving thread is blocked when the
4727  * callback executes.
4728  * @note 2. If the callback throws an exception, the exception will be
4729  * consumed to protect the main loop and a g_critical() warning will
4730  * be issued.
4731  */
4732 void post(const Callback* cb, gint priority = G_PRIORITY_DEFAULT_IDLE,
4733  GMainContext* context = 0);
4734 
4735 /**
4736  * Posts a callback for execution by a glib main loop. It is
4737  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
4738  * has been called. glib >= 2.32 does not require g_thread_init() to
4739  * be called. This function will not throw.
4740  * @param cb The callback object. Ownership is taken of this object,
4741  * and it will be deleted when it has been finished with.
4742  * @param r A Releaser object for automatic disconnection of the
4743  * callback before it executes in the main loop (mainly relevant if
4744  * the callback represents a non-static member function of an object
4745  * which may be destroyed before the callback executes).
4746  * @param priority The priority to be given to the callback in the
4747  * main loop. In ascending order of priorities, priorities are
4748  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
4749  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
4750  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
4751  * callback will appear in the event list in the main loop, not the
4752  * priority which the OS will adopt.
4753  * @param context The glib main loop context in which the callback is
4754  * to be executed (the default of NULL will cause the callback to be
4755  * executed in the main program loop, and this is usually what is
4756  * wanted).
4757  * @exception std::bad_alloc This function might throw std::bad_alloc
4758  * if memory is exhausted and the system throws in that case. If it
4759  * does so, the Callback object will be disposed of.
4760  * @exception Cgu::Thread::MutexError This function might throw
4761  * Cgu:Thread::MutexError if initialisation of the mutex in a
4762  * SafeEmitterArg object constructed by this function fails. If it
4763  * does so, the Callback object will be disposed of. (It is often not
4764  * worth checking for this exception, as it means either memory is
4765  * exhausted or pthread has run out of other resources to create new
4766  * mutexes.)
4767  * @note 1. Cancellation of the receiving thread is blocked when the
4768  * callback executes.
4769  * @note 2. If the callback throws an exception, the exception will be
4770  * consumed to protect the main loop and a g_critical() warning will
4771  * be issued.
4772  * @note 3. By virtue of the Releaser object, it is in theory possible
4773  * (if memory is exhausted and the system throws in that case) that an
4774  * internal SafeEmitterArg object will throw std::bad_alloc when
4775  * emitting/executing the callback in the glib main loop, with the
4776  * result that the relevant callback will not execute (instead the
4777  * exception will be consumed and a g_critical() warning will be
4778  * issued). This is rarely of any relevance because glib will abort
4779  * the program if it is itself unable to obtain memory from the
4780  * operating system. However, where it is relevant, design the
4781  * program so that it is not necessary to provide a releaser object.
4782  */
4783 void post(const Callback* cb, Releaser& r,
4784  gint priority = G_PRIORITY_DEFAULT_IDLE, GMainContext* context = 0);
4785 
4786 
4787 /**
4788  * Posts a callable object for execution by a glib main loop. It is
4789  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
4790  * has been called. glib >= 2.32 does not require g_thread_init() to
4791  * be called.
4792  * @param func A callable object, such as formed by a lambda
4793  * expression or the result of std::bind. It must be fully bound
4794  * (that is, its must take no arguments when called).
4795  * @param priority The priority to be given to the callable object in
4796  * the main loop. In ascending order of priorities, priorities are
4797  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
4798  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
4799  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
4800  * callback will appear in the event list in the main loop, not the
4801  * priority which the OS will adopt
4802  * @param context The glib main loop context in which the callable
4803  * object is to be executed (the default of NULL will cause the
4804  * callback to be executed in the main program loop, and this is
4805  * usually what is wanted).
4806  * @exception std::bad_alloc This function might throw std::bad_alloc
4807  * if memory is exhausted and the system throws in that case (this
4808  * exception will not be thrown if the library has been installed
4809  * using the \--with-glib-memory-slices-no-compat configuration
4810  * option: instead glib will terminate the program if it is unable to
4811  * obtain memory from the operating system).
4812  * @note 1. This function may also throw if the copy or move
4813  * constructor of the callable object throws.
4814  * @note 2. Cancellation of the receiving thread is blocked when the
4815  * callback executes.
4816  * @note 3. If the callback throws an exception, the exception will be
4817  * consumed to protect the main loop and a g_critical() warning will
4818  * be issued.
4819  *
4820  * Since 2.1.0
4821  */
4822 // we need to use enable_if so that where this function is passed a
4823 // pointer to non-const Callback, or some other convertible pointer,
4824 // this templated overload is dropped from the overload set, in order
4825 // to support the Callback pointer overloads of this function. This
4826 // overload calls into the version of this function taking a pointer
4827 // to const Callback in order to perform type erasure.
4828 template <class F,
4829  class = typename std::enable_if<!std::is_convertible<typename std::remove_reference<F>::type,
4830  const Callback*>::value>::type>
4831 void post(F&& func, gint priority = G_PRIORITY_DEFAULT_IDLE,
4832  GMainContext* context = 0) {
4833  post(lambda<>(std::forward<F>(func)), priority, context);
4834 }
4835 
4836 /**
4837  * Posts a callable object for execution by a glib main loop. It is
4838  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
4839  * has been called. glib >= 2.32 does not require g_thread_init() to
4840  * be called.
4841  * @param func A callable object, such as formed by a lambda
4842  * expression or the result of std::bind. It must be fully bound
4843  * (that is, its must take no arguments when called).
4844  * @param r A Releaser object for automatic disconnection of the
4845  * callback before it executes in the main loop (mainly relevant if
4846  * the callback represents or calls into a non-static member function
4847  * of an object which may be destroyed before the callback executes).
4848  * @param priority The priority to be given to the callback in the
4849  * main loop. In ascending order of priorities, priorities are
4850  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
4851  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
4852  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
4853  * callback will appear in the event list in the main loop, not the
4854  * priority which the OS will adopt.
4855  * @param context The glib main loop context in which the callable
4856  * object is to be executed (the default of NULL will cause the
4857  * callback to be executed in the main program loop, and this is
4858  * usually what is wanted).
4859  * @exception std::bad_alloc This function might throw std::bad_alloc
4860  * if memory is exhausted and the system throws in that case.
4861  * @exception Cgu::Thread::MutexError This function might throw
4862  * Cgu:Thread::MutexError if initialisation of the mutex in a
4863  * SafeEmitterArg object constructed by this function fails. (It is
4864  * often not worth checking for this exception, as it means either
4865  * memory is exhausted or pthread has run out of other resources to
4866  * create new mutexes.)
4867  * @note 1. This function may also throw if the copy or move
4868  * constructor of the callable object throws.
4869  * @note 2. Cancellation of the receiving thread is blocked when the
4870  * callback executes.
4871  * @note 3. If the callback throws an exception, the exception will be
4872  * consumed to protect the main loop and a g_critical() warning will
4873  * be issued.
4874  * @note 4. By virtue of the Releaser object, it is in theory possible
4875  * (if memory is exhausted and the system throws in that case) that an
4876  * internal SafeEmitterArg object will throw std::bad_alloc when
4877  * emitting/executing the callback in the glib main loop, with the
4878  * result that the relevant callback will not execute (instead the
4879  * exception will be consumed and a g_critical() warning will be
4880  * issued). This is rarely of any relevance because glib will abort
4881  * the program if it is itself unable to obtain memory from the
4882  * operating system. However, where it is relevant, design the
4883  * program so that it is not necessary to provide a releaser object.
4884  *
4885  * Since 2.1.0
4886  */
4887 // we need to use enable_if so that where this function is passed a
4888 // pointer to non-const Callback, or some other convertible pointer,
4889 // this templated overload is dropped from the overload set, in order
4890 // to support the Callback pointer overloads of this function. This
4891 // overload calls into the version of this function taking a pointer
4892 // to const Callback in order to perform type erasure.
4893 template <class F,
4894  class = typename std::enable_if<!std::is_convertible<typename std::remove_reference<F>::type,
4895  const Callback*>::value>::type>
4896 void post(F&& func, Releaser& r,
4897  gint priority = G_PRIORITY_DEFAULT_IDLE, GMainContext* context = 0) {
4898  post(lambda<>(std::forward<F>(func)), r, priority, context);
4899 }
4900 
4901 } // namespace Callback
4902 
4903 } // namespace Cgu
4904 
4905 #endif
void operator()(typename Cgu::Param< FreeArgs >::ParamType...args) const
Definition: callback.h:985
FunctorArg Functor
Definition: callback.h:784
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1271
CallbackArg< FreeArgs...> * make_ref(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1358
SafeFunctorArg< T...> to_safe_functor(const CallbackArg< T...> *cb)
Definition: callback.h:1258
CallbackArg< FreeArgs...> * make(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1340
FunctorArg(FunctorArg &&f)
Definition: callback.h:1048
This is a smart pointer for managing the lifetime of objects allocated on freestore, with a thread safe reference count.
Definition: shared_ptr.h:644
SafeFunctorArg(const SafeFunctorArg &f)
Definition: callback.h:1157
STL namespace.
Struct which will conditionally convert a reference type to a value type.
Definition: param.h:111
Callback_memfun(T &obj_, MemFunc func_)
Definition: callback.h:1305
Functor class holding a Callback::CallbackArg object.
Definition: callback.h:783
std::unique_ptr< const CallbackArg< T...> > to_unique(const CallbackArg< T...> *cb) noexcept
Definition: callback.h:777
const T & ParamType
Definition: param.h:84
Callback_lambda(L &&l_)
Definition: callback.h:1272
Callback_fun_tuple(Func func_, Args &&...args)
Definition: callback.h:1320
Callback_memfun_tuple(T &obj_, MemFunc func_, Args &&...args)
Definition: callback.h:1289
SafeFunctorArg()
Definition: callback.h:1175
A specialization of std::hash for Cgu::Callback::FunctorArg, Cgu::Callback::SafeFunctorArg, Cgu::GobjHandle, Cgu::GvarHandle, Cgu::IntrusivePtr, Cgu::SharedHandle, Cgu::SharedLockHandle, Cgu::SharedPtr and Cgu::SharedLockPtr so that such objects may be keys of unordered associative containers.
Definition: callback.h:1279
Definition: callback.h:1311
FunctorArg()
Definition: callback.h:1055
SafeFunctorArg SafeFunctor
Definition: callback.h:786
SafeFunctorArg(SafeFunctorArg &&f)
Definition: callback.h:1163
bool operator==(const FunctorArg< T...> &f1, const FunctorArg< T...> &f2) noexcept
Definition: callback.h:798
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1285
bool operator!=(const FunctorArg< T...> &f1, const FunctorArg< T...> &f2) noexcept
Definition: callback.h:808
CallbackArg< FreeArgs...> * lambda(Lambda &&l)
Definition: callback.h:3722
FunctorArg & operator=(FunctorArg &&f)
Definition: callback.h:1001
Definition: callback.h:1266
FunctorArg & operator=(const FunctorArg &f)
Definition: callback.h:994
Definition: application.h:44
auto tuple_apply(Func &&func, const std::tuple< TupleArgs...> &t, OtherArgs &&...args) -> typename std::result_of< Func(const TupleArgs &..., OtherArgs &&...)>::type
Definition: param.h:304
FunctorArg(const FunctorArg &f)
Definition: callback.h:1042
virtual void dispatch(typename Cgu::Param< FreeArgs >::ParamType...args) const =0
SafeFunctorArg & operator=(const SafeFunctorArg &f)
Definition: callback.h:1109
Functor class holding a Callback::CallbackArg object, with thread-safe reference count.
Definition: callback.h:784
bool operator<(const FunctorArg< T...> &f1, const FunctorArg< T...> &f2)
Definition: callback.h:826
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1316
Definition: callback.h:1298
void operator()(typename Cgu::Param< FreeArgs >::ParamType...args) const
Definition: callback.h:1100
CallbackArg()
Definition: callback.h:680
SafeFunctorArg & operator=(SafeFunctorArg &&f)
Definition: callback.h:1116
CallbackArg Callback
Definition: callback.h:567
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1302
virtual ~CallbackArg()
Definition: callback.h:686
The callback interface class.
Definition: callback.h:567
#define CGU_GLIB_MEMORY_SLICES_FUNCS
Definition: cgu_config.h:84
A class used for tracking EmitterArg and SafeEmitterArg connections.
Definition: emitter.h:352
FunctorArg< T...> to_functor(const CallbackArg< T...> *cb)
Definition: callback.h:1218
void post(const Callback *cb, gint priority=G_PRIORITY_DEFAULT_IDLE, GMainContext *context=0)