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