c++-gtk-utils
do_if.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 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_DO_IF_H
40 #define CGU_DO_IF_H
41 
42 /**
43  * @file do_if.h
44  * @brief This file provides utility functions for conditional compilation.
45  *
46  * \#include <c++-gtk-utils/do_if.h>
47  *
48  * From version 1.2.10, the library provides a small subset of
49  * template meta-programming techniques likely to be most relevant to
50  * GUI programming (if something more substantial is required,
51  * something like boost or loki should be used).
52  *
53  * For conditional compilation, the library provides the
54  * Cgu::DoIf::mem_fun() utility functions which will conditionally
55  * compile a call to a non-static class member function if, and only
56  * if, the target object has that function as a member. If it does
57  * not have the member function as a member, the call will just do
58  * nothing rather than generate a compiler error, as it will also if
59  * the target object is const and the member function to be called is
60  * non-const. In addition Cgu::DoIf::fun() will conditionally compile
61  * a call to an ordinary function (or static member function) if, and
62  * only if, the target object is convertible to the type (say, a base
63  * type) held by pointer as the first argument of that function.
64  *
65  * They therefore provide compile-time inheritance checking based on
66  * the static type of the object passed to them. They save dynamic
67  * casting (and therefore run time overhead and the requirement for
68  * target types to have a virtual method) in templated functions when
69  * the static type is all that is necessary to enable type checking to
70  * be carried out.
71  *
72  * This is not just a template curiosity, but enables more generic
73  * programming practices when, say, passing mixins to templated
74  * functions. A templated function can be passed an object as a
75  * template type, and that function can then conditionally call member
76  * functions of objects passed to it. If the object has a particular
77  * function as a member, Cgu::DoIf::mem_fun() will call the function,
78  * and if not it will do nothing without causing a compilation error.
79  * It can be particularly useful for templated set-up or tear-down
80  * functions intended to take a wide variety of different objects with
81  * differing features.
82  *
83  * As mentioned above, Cgu::DoIf::mem_fun() and Cgu::DoIf::fun() will
84  * do nothing if an attempt is made to execute a non-const function on
85  * a const object, as well as if the object type does not match the
86  * function or member function sought to be invoked. If a compilation
87  * failure is wanted in a case of const mismatch instead of doing
88  * nothing, from version 1.2.15 the static assertion
89  * Cgu::DoIf::assert_not_const() can be invoked before the call to a
90  * non-const function is made by Cgu::DoIf::mem_fun() or
91  * Cgu::DoIf::fun().
92  *
93  * Non-static member functions
94  * ---------------------------
95  *
96  * The first argument to be passed to Cgu::DoIf::mem_fun() is the
97  * target object to be tested, the second argument is the non-static
98  * member function which is to be called with respect to that object
99  * if it has the function as a member, and up to two further arguments
100  * can be passed representing the arguments to be provided to that
101  * member function. These arguments may be reference arguments (const
102  * or non-const), and they are passed by a Param struct which uses
103  * template partial specialisation in order to provide automatic type
104  * mapping for arguments, so if they are value arguments they will be
105  * passed by reference to const: therefore, no copying of value
106  * arguments should arise by virtue of routing the calls through
107  * Cgu::DoIf::mem_fun().
108  *
109  * As an example, take a class which uses multiple inheritance to
110  * inherit from Cgu::EmitterArg as a mixin (normally a class would
111  * have an Emitter object as a member, but it can be inherited from).
112  * A container of objects could have the emit() method called on them
113  * in a case where they do inherit from EmitterArg, where the code
114  * does nothing if they do not. For example:
115  * @code
116  * class Calc {
117  * public:
118  * void do_calc(void);
119  * };
120  *
121  * class CalcEmit: public Calc,
122  * public Cgu::EmitterArg<int> {
123  * };
124  *
125  * ... some code blocks elsewhere ...
126  *
127  * template <class T>
128  * void dispatch_calcs(const std::vector<T>& v) {
129  * int count;
130  * typename std::vector<T>::const_iterator iter;
131  * for (count = 0, iter = v.begin();
132  * iter != v.end();
133  * ++count, ++iter) {
134  * iter->do_calc();
135  * Cgu::DoIf::mem_fun(*iter, // object to be tested
136  * &Cgu::EmitterArg<int>::emit, // member function to be conditionally called
137  * count); // argument
138  * }
139  * }
140  * @endcode
141  *
142  * Ordinary functions and static member functions
143  * ----------------------------------------------
144  *
145  * The use of Cgu::DoIf::fun() with normal functions and static member
146  * functions is similar to the use of mem_fun() with non-static member
147  * functions, except that the first argument of the function to be
148  * conditionally called must be a pointer to a type to which the
149  * target object can prospectively be converted. The first argument
150  * to be passed to Cgu::DoIf::fun() is the target object to be tested
151  * and the second argument is the function which is to be
152  * conditionally called if the conversion can be accomplished. If the
153  * function to be conditionally called is so called, the target object
154  * will be passed by pointer to it. Up to two further arguments can
155  * be passed to Cgu::DoIf::fun() representing up to two additional
156  * arguments to be provided to the function to be conditionally
157  * called, which may be reference arguments or value arguments (and if
158  * value arguments they will be passed by reference to const, as in
159  * the case of mem_fun()).
160  *
161  * The use of Cgu::DoIf::fun() with ordinary functions can be useful
162  * for batching a number of calls to be made to a test object. For
163  * example:
164  *
165  * @code
166  * class Calc {
167  * public:
168  * void do_calc();
169  * };
170  *
171  * class CalcEmit: public Calc,
172  * public Cgu::EmitterArg<int> {
173  * public:
174  * void clean_up(int);
175  * };
176  *
177  * ... some code blocks elsewhere ...
178  *
179  * void emit_on_calcs(CalcEmit* c, int count) {
180  * c->emit(count);
181  * c->clean_up(count);
182  * }
183  *
184  * template <class T>
185  * void dispatch_calcs(const std::vector<T>& v) {
186  * int count;
187  * typename std::vector<T>::const_iterator iter;
188  * for (count = 0, iter = v.begin();
189  * iter != v.end();
190  * ++count, ++iter) {
191  * iter->do_calc();
192  * Cgu::DoIf::fun(*iter, // object to be tested against first argument of function to be conditionally called
193  * &emit_on_calcs, // function to be conditionally called
194  * count); // second argument of function to be conditionally called
195  * }
196  * }
197  * @endcode
198  *
199  * Return values
200  * -------------
201  *
202  * If the function to be called returns something other than void and
203  * the function to be conditionally called is not called, then
204  * mem_fun() and fun() pass back a dummy object of the return type
205  * using that type's default constructor. The returned object has no
206  * meaning beyond that in such a case, so it should not be relied on
207  * as holding anything other than its default value on default
208  * construction in a case of failure. This in turn means that any
209  * return value, if not a built-in type, must have a default
210  * constructor.
211  *
212  * Overloaded functions
213  * --------------------
214  *
215  * Where a referenced member function or ordinary function is
216  * overloaded, this may cause difficulties in template type deduction
217  * when mem_fun() or fun() is called. Functions may be overloaded on
218  * numbers of argument without difficulty. For example:
219  * @code
220  * class A {
221  * public:
222  * void do_it(int i);
223  * void do_it(int i, int j);
224  * };
225  * template <class T>
226  * void do_it_if(T& t) {
227  * int i = 1, j = 2;
228  * Cgu::DoIf::mem_fun(t, &A::do_it, i); // OK
229  * Cgu::DoIf::mem_fun(t, &A::do_it, i, j); // OK
230  * }
231  * @endcode
232  * However, they cannot be overloaded on types without explicit
233  * disambiguation when mem_fun() or fun() is called. For example the
234  * following will fail to compile unless explicitly disambiguated:
235  * @code
236  * class A {
237  * public:
238  * void do_it(int i);
239  * void do_it(double d);
240  * };
241  * template <class T>
242  * void do_it_if(T& t) {
243  * int i = 1;
244  * double d = 10.0;
245  * Cgu::DoIf::mem_fun(t, &A::do_it, i); // won't compile
246  * Cgu::DoIf::mem_fun(t, &A::do_it, d); // won't compile
247  * Cgu::DoIf::mem_fun(t, static_cast<void (A::*)(int)>(&A::do_it), i); // OK
248  * Cgu::DoIf::mem_fun(t, static_cast<void (A::*)(double)>(&A::do_it), d); // OK
249  * }
250  * @endcode
251  *
252  * Static assertion
253  * ----------------
254  *
255  * This library also provides the Cgu::DoIf::assert_related_to_type(),
256  * Cgu::DoIf::assert_related_types() and Cgu::DoIf::assert_same_type()
257  * static type-checking assertions. If the matters asserted are not
258  * true, a compile time error in the line where the the functions are
259  * instantiated will occur (with a message that an incomplete type
260  * 'struct DoIf::StaticAssertion<false>' has been used).
261  *
262  * These static assertion functions can be viewed as doing the
263  * opposite of Cgu::DoIf::mem_fun() and Cgu::DoIf::fun(). The
264  * mem_fun() and fun() functions will make a conditional call, and do
265  * nothing if the test condition is not met without a compile time or
266  * run time error, in order to provide compile time polymorphism. On
267  * the other hand, assert_related_to_type(), assert_related_types()
268  * and assert_same_type() cause an explicit compilation error where
269  * the test condition is not met at an ascertainable point in the code
270  * whilst avoiding a slew of incomprehensible error messages from the
271  * compiler. They enable compile time checking of type related
272  * invariants.
273  *
274  * In addition, from version 1.2.15, a Cgu::DoIf::assert_not_const()
275  * static assertion is available.
276  *
277  * The static assertions add nothing to the compiled object code.
278  * They either succeed or fail at compile time.
279  */
280 
281 /**
282  * @namespace Cgu::DoIf
283  * @brief This namespace provides utility functions for conditional compilation.
284  *
285  * \#include <c++-gtk-utils/do_if.h>
286  *
287  * From version 1.2.10, the library provides a small subset of
288  * template meta-programming techniques likely to be most relevant to
289  * GUI programming (if something more substantial is required,
290  * something like boost or loki should be used).
291  *
292  * For conditional compilation, the library provides the
293  * Cgu::DoIf::mem_fun() utility functions which will conditionally
294  * compile a call to a non-static class member function if, and only
295  * if, the target object has that function as a member. If it does
296  * not have the member function as a member, the call will just do
297  * nothing rather than generate a compiler error, as it will also if
298  * the target object is const and the member function to be called is
299  * non-const. In addition Cgu::DoIf::fun() will conditionally compile
300  * a call to an ordinary function (or static member function) if, and
301  * only if, the target object is convertible to the type (say, a base
302  * type) held by pointer as the first argument of that function.
303  *
304  * They therefore provide compile-time inheritance checking based on
305  * the static type of the object passed to them. They save dynamic
306  * casting (and therefore run time overhead and the requirement for
307  * target types to have a virtual method) in templated functions when
308  * the static type is all that is necessary to enable type checking to
309  * be carried out.
310  *
311  * This is not just a template curiosity, but enables more generic
312  * programming practices when, say, passing mixins to templated
313  * functions. A templated function can be passed an object as a
314  * template type, and that function can then conditionally call member
315  * functions of objects passed to it. If the object has a particular
316  * function as a member, Cgu::DoIf::mem_fun() will call the function,
317  * and if not it will do nothing without causing a compilation error.
318  * It can be particularly useful for templated set-up or tear-down
319  * functions intended to take a wide variety of different objects with
320  * differing features.
321  *
322  * As mentioned above, Cgu::DoIf::mem_fun() and Cgu::DoIf::fun() will
323  * do nothing if an attempt is made to execute a non-const function on
324  * a const object, as well as if the object type does not match the
325  * function or member function sought to be invoked. If a compilation
326  * failure is wanted in a case of const mismatch instead of doing
327  * nothing, from version 1.2.15 the static assertion
328  * Cgu::DoIf::assert_not_const() can be invoked before the call to a
329  * non-const function is made by Cgu::DoIf::mem_fun() or
330  * Cgu::DoIf::fun().
331  *
332  * Non-static member functions
333  * ---------------------------
334  *
335  * The first argument to be passed to Cgu::DoIf::mem_fun() is the
336  * target object to be tested, the second argument is the non-static
337  * member function which is to be called with respect to that object
338  * if it has the function as a member, and up to two further arguments
339  * can be passed representing the arguments to be provided to that
340  * member function. These arguments may be reference arguments (const
341  * or non-const), and they are passed by a Param struct which uses
342  * template partial specialisation in order to provide automatic type
343  * mapping for arguments, so if they are value arguments they will be
344  * passed by reference to const: therefore, no copying of value
345  * arguments should arise by virtue of routing the calls through
346  * Cgu::DoIf::mem_fun().
347  *
348  * As an example, take a class which uses multiple inheritance to
349  * inherit from Cgu::EmitterArg as a mixin (normally a class would
350  * have an Emitter object as a member, but it can be inherited from).
351  * A container of objects could have the emit() method called on them
352  * in a case where they do inherit from EmitterArg, where the code
353  * does nothing if they do not. For example:
354  * @code
355  * class Calc {
356  * public:
357  * void do_calc(void);
358  * };
359  *
360  * class CalcEmit: public Calc,
361  * public Cgu::EmitterArg<int> {
362  * };
363  *
364  * ... some code blocks elsewhere ...
365  *
366  * template <class T>
367  * void dispatch_calcs(const std::vector<T>& v) {
368  * int count;
369  * typename std::vector<T>::const_iterator iter;
370  * for (count = 0, iter = v.begin();
371  * iter != v.end();
372  * ++count, ++iter) {
373  * iter->do_calc();
374  * Cgu::DoIf::mem_fun(*iter, // object to be tested
375  * &Cgu::EmitterArg<int>::emit, // member function to be conditionally called
376  * count); // argument
377  * }
378  * }
379  * @endcode
380  *
381  * Ordinary functions and static member functions
382  * ----------------------------------------------
383  *
384  * The use of Cgu::DoIf::fun() with normal functions and static member
385  * functions is similar to the use of mem_fun() with non-static member
386  * functions, except that the first argument of the function to be
387  * conditionally called must be a pointer to a type to which the
388  * target object can prospectively be converted. The first argument
389  * to be passed to Cgu::DoIf::fun() is the target object to be tested
390  * and the second argument is the function which is to be
391  * conditionally called if the conversion can be accomplished. If the
392  * function to be conditionally called is so called, the target object
393  * will be passed by pointer to it. Up to two further arguments can
394  * be passed to Cgu::DoIf::fun() representing up to two additional
395  * arguments to be provided to the function to be conditionally
396  * called, which may be reference arguments or value arguments (and if
397  * value arguments they will be passed by reference to const, as in
398  * the case of mem_fun()).
399  *
400  * The use of Cgu::DoIf::fun() with ordinary functions can be useful
401  * for batching a number of calls to be made to a test object. For
402  * example:
403  *
404  * @code
405  * class Calc {
406  * public:
407  * void do_calc();
408  * };
409  *
410  * class CalcEmit: public Calc,
411  * public Cgu::EmitterArg<int> {
412  * public:
413  * void clean_up(int);
414  * };
415  *
416  * ... some code blocks elsewhere ...
417  *
418  * void emit_on_calcs(CalcEmit* c, int count) {
419  * c->emit(count);
420  * c->clean_up(count);
421  * }
422  *
423  * template <class T>
424  * void dispatch_calcs(const std::vector<T>& v) {
425  * int count;
426  * typename std::vector<T>::const_iterator iter;
427  * for (count = 0, iter = v.begin();
428  * iter != v.end();
429  * ++count, ++iter) {
430  * iter->do_calc();
431  * Cgu::DoIf::fun(*iter, // object to be tested against first argument of function to be conditionally called
432  * &emit_on_calcs, // function to be conditionally called
433  * count); // second argument of function to be conditionally called
434  * }
435  * }
436  * @endcode
437  *
438  * Return values
439  * -------------
440  *
441  * If the function to be called returns something other than void and
442  * the function to be conditionally called is not called, then
443  * mem_fun() and fun() pass back a dummy object of the return type
444  * using that type's default constructor. The returned object has no
445  * meaning beyond that in such a case, so it should not be relied on
446  * as holding anything other than its default value on default
447  * construction in a case of failure. This in turn means that any
448  * return value, if not a built-in type, must have a default
449  * constructor.
450  *
451  * Overloaded functions
452  * --------------------
453  *
454  * Where a referenced member function or ordinary function is
455  * overloaded, this may cause difficulties in template type deduction
456  * when mem_fun() or fun() is called. Functions may be overloaded on
457  * numbers of argument without difficulty. For example:
458  * @code
459  * class A {
460  * public:
461  * void do_it(int i);
462  * void do_it(int i, int j);
463  * };
464  * template <class T>
465  * void do_it_if(T& t) {
466  * int i = 1, j = 2;
467  * Cgu::DoIf::mem_fun(t, &A::do_it, i); // OK
468  * Cgu::DoIf::mem_fun(t, &A::do_it, i, j); // OK
469  * }
470  * @endcode
471  * However, they cannot be overloaded on types without explicit
472  * disambiguation when mem_fun() or fun() is called. For example the
473  * following will fail to compile unless explicitly disambiguated:
474  * @code
475  * class A {
476  * public:
477  * void do_it(int i);
478  * void do_it(double d);
479  * };
480  * template <class T>
481  * void do_it_if(T& t) {
482  * int i = 1;
483  * double d = 10.0;
484  * Cgu::DoIf::mem_fun(t, &A::do_it, i); // won't compile
485  * Cgu::DoIf::mem_fun(t, &A::do_it, d); // won't compile
486  * Cgu::DoIf::mem_fun(t, static_cast<void (A::*)(int)>(&A::do_it), i); // OK
487  * Cgu::DoIf::mem_fun(t, static_cast<void (A::*)(double)>(&A::do_it), d); // OK
488  * }
489  * @endcode
490  *
491  * Static assertion
492  * ----------------
493  *
494  * This library also provides the Cgu::DoIf::assert_related_to_type(),
495  * Cgu::DoIf::assert_related_types() and Cgu::DoIf::assert_same_type()
496  * static type-checking assertions. If the matters asserted are not
497  * true, a compile time error in the line where the the functions are
498  * instantiated will occur (with a message that an incomplete type
499  * 'struct DoIf::StaticAssertion<false>' has been used).
500  *
501  * These static assertion functions can be viewed as doing the
502  * opposite of Cgu::DoIf::mem_fun() and Cgu::DoIf::fun(). The
503  * mem_fun() and fun() functions will make a conditional call, and do
504  * nothing if the test condition is not met without a compile time or
505  * run time error, in order to provide compile time polymorphism. On
506  * the other hand, assert_related_to_type(), assert_related_types()
507  * and assert_same_type() cause an explicit compilation error where
508  * the test condition is not met at an ascertainable point in the code
509  * whilst avoiding a slew of incomprehensible error messages from the
510  * compiler. They enable compile time checking of type related
511  * invariants.
512  *
513  * In addition, from version 1.2.15, a Cgu::DoIf::assert_not_const()
514  * static assertion is available.
515  *
516  * The static assertions add nothing to the compiled object code.
517  * They either succeed or fail at compile time.
518  */
519 
520 #include <c++-gtk-utils/param.h>
522 
523 namespace Cgu {
524 
525 namespace DoIf {
526 
527 /**
528  * @class RelatedTest do_if.h c++-gtk-utils/do_if.h
529  * @brief Class for compile time testing of inheritance relationships
530  * @sa DoIf::mem_fun DoIf::fun
531  *
532  * This class provides a compile time test of whether the Obj class
533  * template parameter type is related to the Base class template
534  * parameter type by public derivation, or they are of the same type:
535  * the 'value' public member will be true if they are, otherwise
536  * false. Everything in it comprises a compile time constant so that
537  * 'value' can be used as a template parameter for conditional
538  * complation. Because 'RelatedTest' has a static member named
539  * 'value', it can also be used with boost's 'enable_if' templates.
540  *
541  * This class tests convertibility, and constness is not discarded in
542  * making the test. Whilst a non-const type passed as the second
543  * template parameter will (if the other conditions referred to above
544  * are met) be shown as related to a const base type or const same
545  * type specified as the first template parameter type, the reverse is
546  * not true. This ensures that the DoIf::mem_fun() and DoIf::fun()
547  * conditional compilation functions work correctly.
548  *
549  * Since 1.2.10
550  */
551 
552 template<class Base, class Obj>
553 class RelatedTest {
554 
555  typedef char yes; // sizeof(yes) == 1
556  typedef char no[2]; // sizeof(no) == 2
557 
558  // overloaded functions can have different return types: this is necessary here
559  // as it identifies which of the two functions has been chosen by the compiler
560  // on overload resolution. Since these functions are never called (they are just
561  // passed to the sizeof operator) we don't need function bodies.
562  static yes& test(Base*);
563  static no& test(...);
564 
565 public:
566 /**
567  * A compile time constant which indicates whether the Obj class
568  * template parameter type is related to the Base class template
569  * parameter type by public derivation, or they are of the same type.
570  * Because it is a compile time constant it can be used as a template
571  * parameter and therefore for conditional compilation.
572  *
573  * This constant specifies convertibility, and constness is not
574  * discarded in making the test. Whilst a non-const type passed as
575  * the second template parameter will (if the other conditions
576  * referred to above are met) be shown as related to a const base type
577  * or const same type specified as the first template parameter type,
578  * the reverse is not true. This ensures that the DoIf::mem_fun() and
579  * DoIf::fun() conditional compilation functions work correctly.
580  *
581  * Since 1.2.10
582  */
583  static const bool value = sizeof(test(static_cast<Obj*>(0))) == sizeof(yes)
584  && sizeof(test(static_cast<void*>(0))) == sizeof(no);
585 };
586 
587 /**
588  * @class StaticAssertion do_if.h c++-gtk-utils/do_if.h
589  * @brief Class for compile time assertion that a statement is true
590  * @sa DoIf::RelatedTest DoIf::assert_related_to_type() DoIf::assert_related_types() DoIf::assert_same_type() and DoIf::assert_not_const()
591  *
592  * This class will provide a compile time error if an attempt to
593  * instantiate it is made when the template argument is false. It is
594  * used by the assert_related_to_type(), assert_related_types(),
595  * assert_same_type() and assert_not_const() static type-checking
596  * assertions.
597  *
598  * Since 1.2.10
599  */
600 template <bool>
602 
603 template <>
604 struct StaticAssertion<true> {};
605 
606 /**
607  * @class RemoveConst do_if.h c++-gtk-utils/do_if.h
608  * @brief Class for removing a const qualifier
609  *
610  * This class removes a const qualifier. It is used by the
611  * assert_not_const() static type-checking assertion.
612  *
613  * Since 1.2.15
614  */
615 template <class T>
616 struct RemoveConst {
617  typedef T Type;
618 };
619 
620 template <class T>
621 struct RemoveConst<const T> {
622  typedef T Type;
623 };
624 
625 /**
626  * This function provides a compile time assertion that the static
627  * type of the second argument passed to it is related to (that is,
628  * either the same as or publicly derived from) the static type of the
629  * first argument. If it is not, a compile time error in the line
630  * where the assertion is made will occur (with a message that an
631  * incomplete type 'struct DoIf::StaticAssertion<false>' has been
632  * used, and the line at which this function is reported as
633  * instantiated will be the line at which the assertion failed).
634  *
635  * For example 'Cgu::DoIf::assert_related_to_type(a, b)' will fail to
636  * compile unless the static type of 'b' is the same as or publicly
637  * derived from the static type of 'a'. In making this test,
638  * constness is discarded and not taken into account.
639  *
640  * See assert_related_types() for a test where the ordering of the
641  * arguments is not significant.
642  *
643  * This function can be viewed as doing the opposite of
644  * Cgu::DoIf::mem_fun() and Cgu::DoIf::fun(): it causes a compilation
645  * error where the test is not met, rather than doing nothing.
646  * However, unlike those functions, as mentioned above
647  * assert_related_to_type() discards constness in making the test.
648  *
649  * It generates no object code, and is therefore thread safe and does
650  * not throw.
651  *
652  * Since 1.2.10
653  */
654 template <class Base, class Obj>
655 void assert_related_to_type(const Base& b, const Obj& o) {
657 }
658 
659 /**
660  * This function provides a compile time assertion that the static
661  * type of the argument passed to it is related to (that is, either
662  * the same as or publicly derived from) the type given as the
663  * explicit template parameter to the function call. If it is not, a
664  * compile time error in the line where the assertion is made will
665  * occur (with a message that an incomplete type 'struct
666  * DoIf::StaticAssertion<false>' has been used, and the line at which
667  * this function is reported as instantiated will be the line at which
668  * the assertion failed).
669  *
670  * For example 'Cgu::DoIf::assert_related_to_type<A>(x)' will fail to
671  * compile unless the static type of 'x' is the same as or publicly
672  * derived from type A. In making this test, constness is discarded
673  * and not taken into account.
674  *
675  * This function can be viewed as doing the opposite of
676  * Cgu::DoIf::mem_fun() and Cgu::DoIf::fun(): it causes a compilation
677  * error where the test is not met, rather than doing nothing.
678  * However, unlike those functions, as mentioned above
679  * assert_related_to_type() discards constness in making the test.
680  *
681  * It generates no object code, and is therefore thread safe and does
682  * not throw.
683  *
684  * Since 1.2.10
685  */
686 template <class Base, class Obj>
687 void assert_related_to_type(const Obj& o) {
689 }
690 
691 /**
692  * This function provides a compile time assertion that the static
693  * type of the first argument passed to it is the same as the static
694  * type of the second argument. If it is not, a compile time error in
695  * the line where the assertion is made will occur (with a message
696  * that an incomplete type 'struct DoIf::StaticAssertion<false>' has
697  * been used, and the line at which this function is reported as
698  * instantiated will be the line at which the assertion failed).
699  *
700  * For example 'Cgu::DoIf::assert_same_type(a, b)' will fail to
701  * compile unless the static types of 'a' and 'b' are the same. In
702  * making this test, constness is discarded and not taken into
703  * account: types can be the same even if one is const and the other
704  * is not.
705  *
706  * It generates no object code, and is therefore thread safe and does
707  * not throw.
708  *
709  * Since 1.2.10
710  */
711 template <class T1, class T2>
712 void assert_same_type(const T1& t1, const T2& t2) {
714 }
715 
716 /**
717  * This function provides a compile time assertion that the static
718  * type of the argument passed to it is the same as the type given as
719  * the explicit template parameter to the function call. If it is
720  * not, a compile time error in the line where the assertion is made
721  * will occur (with a message that an incomplete type 'struct
722  * DoIf::StaticAssertion<false>' has been used, and the line at which
723  * this function is reported as instantiated will be the line at which
724  * the assertion failed).
725  *
726  * For example 'Cgu::DoIf::assert_same_type<A>(x)' will fail to
727  * compile unless the static type of 'x' is type A. In making this
728  * test, constness is discarded and not taken into account: types can
729  * be the same even if one is const and the other is not.
730  *
731  * It generates no object code, and is therefore thread safe and does
732  * not throw.
733  *
734  * Earlier versions of this function had a bug. A const type could
735  * not be specified as the explicit template argument
736  * (Cgu::DoIf::assert_same_type<const A>(x) would not work). This was
737  * fixed in version 1.2.15.
738  *
739  * Since 1.2.10
740  */
741 template <class T1, class T2>
742 void assert_same_type(const T2& t2) {
743  // in the second conditional test, make T2 const in case the user
744  // specifies a const T1 parameter type
746 }
747 
748 /**
749  * This function provides a compile time assertion that the static
750  * type of the arguments passed are related to each other (that is,
751  * either they are the same or one is publicly derived from the
752  * other). If they are not, a compile time error in the line where
753  * the assertion is made will occur (with a message that an incomplete
754  * type 'struct DoIf::StaticAssertion<false>' has been used, and the
755  * line at which this function is reported as instantiated will be the
756  * line at which the assertion failed).
757  *
758  * For example 'Cgu::DoIf::assert_related_types(a, b)' will fail to
759  * compile unless the static types of 'a' and 'b' are the same or one
760  * of the static types is publicly derived from the other. In making
761  * this test, constness is discarded and not taken into account: types
762  * can be related even if one is const and the other is not.
763  *
764  * See assert_related_to_type() for a test where the ordering of the
765  * arguments is significant, so that which of them must be the base
766  * type can be stated.
767  *
768  * This function can be viewed as doing the opposite of
769  * Cgu::DoIf::mem_fun() and Cgu::DoIf::fun(): it causes a compilation
770  * error where the test is not met, rather than doing nothing.
771  * However, unlike those functions, as mentioned above
772  * assert_related_types() discards constness in making the test.
773  *
774  * It generates no object code, and is therefore thread safe and does
775  * not throw.
776  *
777  * Since 1.2.10
778  */
779 template <class T1, class T2>
780 void assert_related_types(const T1& t1, const T2& t2) {
782 }
783 
784 /**
785  * This function provides a compile time assertion that the static
786  * type of the argument passed is not const. If it is, a compile time
787  * error in the line where the assertion is made will occur (with a
788  * message that an incomplete type 'struct
789  * DoIf::StaticAssertion<false>' has been used, and the line at which
790  * this function is reported as instantiated will be the line at which
791  * the assertion failed).
792  *
793  * For example 'Cgu::DoIf::assert_not_const(a)' will fail to compile
794  * unless the static type of 'a' is not const.
795  *
796  * It generates no object code, and is therefore thread safe and does
797  * not throw.
798  *
799  * Since 1.2.15
800  */
801 template <class T>
802 void assert_not_const(T& t) {
804 }
805 
806 /**
807  * @class SucceedOnTrue do_if.h c++-gtk-utils/do_if.h
808  * @brief Struct which provides a type 'T' (typedef'ed to void*) if its template parameter is true
809  * @sa SucceedOnFalse mem_fun fun
810  *
811  * This struct provides a public type 'T' (typedef'ed to void*) if the
812  * template parameter passed to it is true, in order to provide
813  * compile time conditional compilation using template SFINAE
814  * (substitution failure is not an error). It is intended for use
815  * with the 'value' member of the RelatedTest class, but it can be
816  * used with any other compile time constant for conditional
817  * compilation purposes.
818  *
819  * Since 1.2.10
820  */
821 template <bool value>
822 struct SucceedOnTrue {};
823 
824 template <>
825 struct SucceedOnTrue<true> {
826  typedef void* T;
827 };
828 
829 /**
830  * @class SucceedOnFalse do_if.h c++-gtk-utils/do_if.h
831  * @brief Struct which provides a type 'T' (typedef'ed to void*) if its template parameter is false
832  * @sa SucceedOnTrue mem_fun fun
833  *
834  * This struct provides a public type 'T' (typedef'ed to void*) if the
835  * template parameter passed to it is false, in order to provide
836  * compile time conditional compilation using template SFINAE
837  * (substitution failure is not an error). It is intended for use
838  * with the 'value' member of the RelatedTest class, but it can be
839  * used with any other compile time constant for conditional
840  * compilation purposes.
841  *
842  * Since 1.2.10
843  */
844 
845 template <bool value>
846 struct SucceedOnFalse {};
847 
848 template <>
849 struct SucceedOnFalse<false> {
850  typedef void* T;
851 };
852 
853 /* the mem_fun() forwarding functions */
854 
855 /* return value and two args */
856 /**
857  * This function overload conditionally executes the member function
858  * passed as the second argument if the class object passed as the
859  * first argument has it as a member (say by derivation). This
860  * function is thread safe if the referenced member function is thread
861  * safe. It does not throw unless the referenced member function
862  * throws or (if its arguments are not built-in types nor reference
863  * arguments) the copy constructor of one of the member function's
864  * arguments throws. Ignore the last parameter: it is a dummy
865  * argument included to achieve conditional compilation via SFINAE.
866  * @return The result of the function call.
867  *
868  * Since 1.2.10
869  */
870 template <class Base, class Obj, class Ret, class Arg1, class Arg2>
871 Ret mem_fun(Obj& obj,
872  Ret (Base::*func)(Arg1, Arg2),
873  typename Cgu::Param<Arg1>::ParamType arg1,
874  typename Cgu::Param<Arg2>::ParamType arg2,
875  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
876  return (obj.*func)(arg1, arg2);
877 }
878 
879 /**
880  * This function overload conditionally does nothing if the class
881  * object passed as the first argument does not have the member
882  * function passed as the second argument as a member. This function
883  * is thread safe if the return type's default constructor is thread
884  * safe. It does not throw unless the return type's default
885  * constructor throws. Ignore the last parameter: it is a dummy
886  * argument included to achieve conditional compilation via SFINAE.
887  * @return An empty object obtained by calling the return type's
888  * default constructor.
889  *
890  * Since 1.2.10
891  */
892 template <class Base, class Obj, class Ret, class Arg1, class Arg2>
893 Ret mem_fun(Obj&,
894  Ret (Base::*)(Arg1, Arg2),
897  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
898  return Ret();
899 }
900 
901 /* return value and one arg */
902 /**
903  * This function overload conditionally executes the member function
904  * passed as the second argument if the class object passed as the
905  * first argument has it as a member (say by derivation). This
906  * function is thread safe if the referenced member function is thread
907  * safe. It does not throw unless the referenced member function
908  * throws or (if its argument is not a built-in type nor a reference
909  * argument) the copy constructor of the member function's argument
910  * throws. Ignore the last parameter: it is a dummy argument included
911  * to achieve conditional compilation via SFINAE.
912  * @return The result of the function call.
913  *
914  * Since 1.2.10
915  */
916 template <class Base, class Obj, class Ret, class Arg>
917 Ret mem_fun(Obj& obj,
918  Ret (Base::*func)(Arg),
919  typename Cgu::Param<Arg>::ParamType arg,
920  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
921  return (obj.*func)(arg);
922 }
923 
924 /**
925  * This function overload conditionally does nothing if the class
926  * object passed as the first argument does not have the member
927  * function passed as the second argument as a member. This function
928  * is thread safe if the return type's default constructor is thread
929  * safe. It does not throw unless the return type's default
930  * constructor throws. Ignore the last parameter: it is a dummy
931  * argument included to achieve conditional compilation via SFINAE.
932  * @return An empty object obtained by calling the return type's
933  * default constructor.
934  *
935  * Since 1.2.10
936  */
937 template <class Base, class Obj, class Ret, class Arg>
938 Ret mem_fun(Obj&,
939  Ret (Base::*)(Arg),
941  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
942  return Ret();
943 }
944 
945 
946 /* return value and no arg */
947 /**
948  * This function overload conditionally executes the member function
949  * passed as the second argument if the class object passed as the
950  * first argument has it as a member (say by derivation). This
951  * function is thread safe if the referenced member function is thread
952  * safe. It does not throw unless the referenced member function
953  * throws. Ignore the last parameter: it is a dummy argument included
954  * to achieve conditional compilation via SFINAE.
955  * @return The result of the function call.
956  *
957  * Since 1.2.10
958  */
959 template <class Base, class Obj, class Ret>
960 Ret mem_fun(Obj& obj,
961  Ret (Base::*func)(),
962  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
963  return (obj.*func)();
964 }
965 
966 /**
967  * This function overload conditionally does nothing if the class
968  * object passed as the first argument does not have the member
969  * function passed as the second argument as a member. This function
970  * is thread safe if the return type's default constructor is thread
971  * safe. It does not throw unless the return type's default
972  * constructor throws. Ignore the last parameter: it is a dummy
973  * argument included to achieve conditional compilation via SFINAE.
974  * @return An empty object obtained by calling the return type's
975  * default constructor.
976  *
977  * Since 1.2.10
978  */
979 template <class Base, class Obj, class Ret>
980 Ret mem_fun(Obj&,
981  Ret (Base::*)(),
982  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
983  return Ret();
984 }
985 
986 /* no return value and two args */
987 /**
988  * This function overload conditionally executes the member function
989  * passed as the second argument if the class object passed as the
990  * first argument has it as a member (say by derivation). This
991  * function is thread safe if the referenced member function is thread
992  * safe. It does not throw unless the referenced member function
993  * throws or (if its arguments are not built-in types nor reference
994  * arguments) the copy constructor of one of the member function's
995  * arguments throws. Ignore the last parameter: it is a dummy
996  * argument included to achieve conditional compilation via SFINAE.
997  *
998  * Since 1.2.10
999  */
1000 template <class Base, class Obj, class Arg1, class Arg2>
1001 void mem_fun(Obj& obj,
1002  void (Base::*func)(Arg1, Arg2),
1003  typename Cgu::Param<Arg1>::ParamType arg1,
1004  typename Cgu::Param<Arg2>::ParamType arg2,
1005  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1006  (obj.*func)(arg1, arg2);
1007 }
1008 
1009 /**
1010  * This function overload conditionally does nothing if the class
1011  * object passed as the first argument does not have the member
1012  * function passed as the second argument as a member. This function
1013  * is thread safe. It does not throw. Ignore the last parameter: it
1014  * is a dummy argument included to achieve conditional compilation via
1015  * SFINAE.
1016  *
1017  * Since 1.2.10
1018  */
1019 template <class Base, class Obj, class Arg1, class Arg2>
1020 void mem_fun(Obj&,
1021  void (Base::*)(Arg1, Arg2),
1022  typename Cgu::Param<Arg1>::ParamType,
1023  typename Cgu::Param<Arg2>::ParamType,
1024  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1025 
1026 /* no return value and one arg */
1027 /**
1028  * This function overload conditionally executes the member function
1029  * passed as the second argument if the class object passed as the
1030  * first argument has it as a member (say by derivation). This
1031  * function is thread safe if the referenced member function is thread
1032  * safe. It does not throw unless the referenced member function
1033  * throws or (if its argument is not a built-in type nor a reference
1034  * argument) the copy constructor of the member function's argument
1035  * throws. Ignore the last parameter: it is a dummy argument included
1036  * to achieve conditional compilation via SFINAE.
1037  *
1038  * Since 1.2.10
1039  */
1040 template <class Base, class Obj, class Arg>
1041 void mem_fun(Obj& obj,
1042  void (Base::*func)(Arg),
1043  typename Cgu::Param<Arg>::ParamType arg,
1044  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1045  (obj.*func)(arg);
1046 }
1047 
1048 /**
1049  * This function overload conditionally does nothing if the class
1050  * object passed as the first argument does not have the member
1051  * function passed as the second argument as a member. This function
1052  * is thread safe. It does not throw. Ignore the last parameter: it
1053  * is a dummy argument included to achieve conditional compilation via
1054  * SFINAE.
1055  *
1056  * Since 1.2.10
1057  */
1058 template <class Base, class Obj, class Arg>
1059 void mem_fun(Obj&,
1060  void (Base::*)(Arg),
1061  typename Cgu::Param<Arg>::ParamType,
1062  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1063 
1064 /* no return value and no arg */
1065 /**
1066  * This function overload conditionally executes the member function
1067  * passed as the second argument if the class object passed as the
1068  * first argument has it as a member (say by derivation). This
1069  * function is thread safe if the referenced member function is thread
1070  * safe. It does not throw unless the referenced member function
1071  * throws. Ignore the last parameter: it is a dummy argument included
1072  * to achieve conditional compilation via SFINAE.
1073  *
1074  * Since 1.2.10
1075  */
1076 template <class Base, class Obj>
1077 void mem_fun(Obj& obj,
1078  void (Base::*func)(),
1079  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1080  (obj.*func)();
1081 }
1082 
1083 /**
1084  * This function overload conditionally does nothing if the class
1085  * object passed as the first argument does not have the member
1086  * function passed as the second argument as a member. This function
1087  * is thread safe. It does not throw. Ignore the last parameter: it
1088  * is a dummy argument included to achieve conditional compilation via
1089  * SFINAE.
1090  *
1091  * Since 1.2.10
1092  */
1093 template <class Base, class Obj>
1094 void mem_fun(Obj&,
1095  void (Base::*)(),
1096  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1097 
1098 /* for const member functions */
1099 
1100 /* return value and two args */
1101 /**
1102  * This function overload conditionally executes the member function
1103  * passed as the second argument if the class object passed as the
1104  * first argument has it as a member (say by derivation). This
1105  * function is thread safe if the referenced member function is thread
1106  * safe. It does not throw unless the referenced member function
1107  * throws or (if its arguments are not built-in types nor reference
1108  * arguments) the copy constructor of one of the member function's
1109  * arguments throws. Ignore the last parameter: it is a dummy
1110  * argument included to achieve conditional compilation via SFINAE.
1111  * @return The result of the function call.
1112  *
1113  * Since 1.2.10
1114  */
1115 template <class Base, class Obj, class Ret, class Arg1, class Arg2>
1116 Ret mem_fun(const Obj& obj,
1117  Ret (Base::*func)(Arg1, Arg2) const,
1118  typename Cgu::Param<Arg1>::ParamType arg1,
1119  typename Cgu::Param<Arg2>::ParamType arg2,
1120  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1121  return (obj.*func)(arg1, arg2);
1122 }
1123 
1124 /**
1125  * This function overload conditionally does nothing if the class
1126  * object passed as the first argument does not have the member
1127  * function passed as the second argument as a member. This function
1128  * is thread safe if the return type's default constructor is thread
1129  * safe. It does not throw unless the return type's default
1130  * constructor throws. Ignore the last parameter: it is a dummy
1131  * argument included to achieve conditional compilation via SFINAE.
1132  * @return An empty object obtained by calling the return type's
1133  * default constructor.
1134  *
1135  * Since 1.2.10
1136  */
1137 template <class Base, class Obj, class Ret, class Arg1, class Arg2>
1138 Ret mem_fun(const Obj&,
1139  Ret (Base::*)(Arg1, Arg2) const,
1140  typename Cgu::Param<Arg1>::ParamType,
1141  typename Cgu::Param<Arg2>::ParamType,
1142  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
1143  return Ret();
1144 }
1145 
1146 /* return value and one arg */
1147 /**
1148  * This function overload conditionally executes the member function
1149  * passed as the second argument if the class object passed as the
1150  * first argument has it as a member (say by derivation). This
1151  * function is thread safe if the referenced member function is thread
1152  * safe. It does not throw unless the referenced member function
1153  * throws or (if its argument is not a built-in type nor a reference
1154  * argument) the copy constructor of the member function's argument
1155  * throws. Ignore the last parameter: it is a dummy argument included
1156  * to achieve conditional compilation via SFINAE.
1157  * @return The result of the function call.
1158  *
1159  * Since 1.2.10
1160  */
1161 template <class Base, class Obj, class Ret, class Arg>
1162 Ret mem_fun(const Obj& obj,
1163  Ret (Base::*func)(Arg) const,
1164  typename Cgu::Param<Arg>::ParamType arg,
1165  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1166  return (obj.*func)(arg);
1167 }
1168 
1169 /**
1170  * This function overload conditionally does nothing if the class
1171  * object passed as the first argument does not have the member
1172  * function passed as the second argument as a member. This function
1173  * is thread safe if the return type's default constructor is thread
1174  * safe. It does not throw unless the return type's default
1175  * constructor throws. Ignore the last parameter: it is a dummy
1176  * argument included to achieve conditional compilation via SFINAE.
1177  * @return An empty object obtained by calling the return type's
1178  * default constructor.
1179  *
1180  * Since 1.2.10
1181  */
1182 template <class Base, class Obj, class Ret, class Arg>
1183 Ret mem_fun(const Obj&,
1184  Ret (Base::*)(Arg) const,
1185  typename Cgu::Param<Arg>::ParamType,
1186  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
1187  return Ret();
1188 }
1189 
1190 /* return value and no arg */
1191 /**
1192  * This function overload conditionally executes the member function
1193  * passed as the second argument if the class object passed as the
1194  * first argument has it as a member (say by derivation). This
1195  * function is thread safe if the referenced member function is thread
1196  * safe. It does not throw unless the referenced member function
1197  * throws. Ignore the last parameter: it is a dummy argument included
1198  * to achieve conditional compilation via SFINAE.
1199  * @return The result of the function call.
1200  *
1201  * Since 1.2.10
1202  */
1203 template <class Base, class Obj, class Ret>
1204 Ret mem_fun(const Obj& obj,
1205  Ret (Base::*func)() const,
1206  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1207  return (obj.*func)();
1208 }
1209 
1210 /**
1211  * This function overload conditionally does nothing if the class
1212  * object passed as the first argument does not have the member
1213  * function passed as the second argument as a member. This function
1214  * is thread safe if the return type's default constructor is thread
1215  * safe. It does not throw unless the return type's default
1216  * constructor throws. Ignore the last parameter: it is a dummy
1217  * argument included to achieve conditional compilation via SFINAE.
1218  * @return An empty object obtained by calling the return type's
1219  * default constructor.
1220  *
1221  * Since 1.2.10
1222  */
1223 template <class Base, class Obj, class Ret>
1224 Ret mem_fun(const Obj&,
1225  Ret (Base::*)() const,
1226  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
1227  return Ret();
1228 }
1229 
1230 /* no return value and two args */
1231 /**
1232  * This function overload conditionally executes the member function
1233  * passed as the second argument if the class object passed as the
1234  * first argument has it as a member (say by derivation). This
1235  * function is thread safe if the referenced member function is thread
1236  * safe. It does not throw unless the referenced member function
1237  * throws or (if its arguments are not built-in types nor reference
1238  * arguments) the copy constructor of one of the member function's
1239  * arguments throws. Ignore the last parameter: it is a dummy
1240  * argument included to achieve conditional compilation via SFINAE.
1241  *
1242  * Since 1.2.10
1243  */
1244 template <class Base, class Obj, class Arg1, class Arg2>
1245 void mem_fun(const Obj& obj,
1246  void (Base::*func)(Arg1, Arg2) const,
1247  typename Cgu::Param<Arg1>::ParamType arg1,
1248  typename Cgu::Param<Arg2>::ParamType arg2,
1249  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1250  (obj.*func)(arg1, arg2);
1251 }
1252 
1253 /**
1254  * This function overload conditionally does nothing if the class
1255  * object passed as the first argument does not have the member
1256  * function passed as the second argument as a member. This function
1257  * is thread safe. It does not throw. Ignore the last parameter: it
1258  * is a dummy argument included to achieve conditional compilation via
1259  * SFINAE.
1260  *
1261  * Since 1.2.10
1262  */
1263 template <class Base, class Obj, class Arg1, class Arg2>
1264 void mem_fun(const Obj&,
1265  void (Base::*)(Arg1, Arg2) const,
1266  typename Cgu::Param<Arg1>::ParamType,
1267  typename Cgu::Param<Arg2>::ParamType,
1268  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1269 
1270 /* no return value and one arg */
1271 /**
1272  * This function overload conditionally executes the member function
1273  * passed as the second argument if the class object passed as the
1274  * first argument has it as a member (say by derivation). This
1275  * function is thread safe if the referenced member function is thread
1276  * safe. It does not throw unless the referenced member function
1277  * throws or (if its argument is not a built-in type nor a reference
1278  * argument) the copy constructor of the member function's argument
1279  * throws. Ignore the last parameter: it is a dummy argument included
1280  * to achieve conditional compilation via SFINAE.
1281  *
1282  * Since 1.2.10
1283  */
1284 template <class Base, class Obj, class Arg>
1285 void mem_fun(const Obj& obj,
1286  void (Base::*func)(Arg) const,
1287  typename Cgu::Param<Arg>::ParamType arg,
1288  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1289  (obj.*func)(arg);
1290 }
1291 
1292 /**
1293  * This function overload conditionally does nothing if the class
1294  * object passed as the first argument does not have the member
1295  * function passed as the second argument as a member. This function
1296  * is thread safe. It does not throw. Ignore the last parameter: it
1297  * is a dummy argument included to achieve conditional compilation via
1298  * SFINAE.
1299  *
1300  * Since 1.2.10
1301  */
1302 template <class Base, class Obj, class Arg>
1303 void mem_fun(const Obj&,
1304  void (Base::*)(Arg) const,
1305  typename Cgu::Param<Arg>::ParamType,
1306  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1307 
1308 /* no return value and no arg */
1309 /**
1310  * This function overload conditionally executes the member function
1311  * passed as the second argument if the class object passed as the
1312  * first argument has it as a member (say by derivation). This
1313  * function is thread safe if the referenced member function is thread
1314  * safe. It does not throw unless the referenced member function
1315  * throws. Ignore the last parameter: it is a dummy argument included
1316  * to achieve conditional compilation via SFINAE.
1317  *
1318  * Since 1.2.10
1319  */
1320 template <class Base, class Obj>
1321 void mem_fun(const Obj& obj,
1322  void (Base::*func)() const,
1323  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1324  (obj.*func)();
1325 }
1326 
1327 /**
1328  * This function overload conditionally does nothing if the class
1329  * object passed as the first argument does not have the member
1330  * function passed as the second argument as a member. This function
1331  * is thread safe. It does not throw. Ignore the last parameter: it
1332  * is a dummy argument included to achieve conditional compilation via
1333  * SFINAE.
1334  *
1335  * Since 1.2.10
1336  */
1337 template <class Base, class Obj>
1338 void mem_fun(const Obj&,
1339  void (Base::*)() const,
1340  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1341 
1342 /* for ordinary functions and static member functions */
1343 
1344 /* return value and two args */
1345 /**
1346  * This function overload conditionally executes the function passed
1347  * as the second argument if the object passed as the first argument
1348  * relates to (ie is an instance of or derived from) the type to which
1349  * the first argument of the function to be conditionally executed is
1350  * a pointer. This function is thread safe if the referenced function
1351  * to be called is thread safe. It does not throw unless the
1352  * referenced function throws or (if its arguments are not built-in
1353  * types nor reference arguments) the copy constructor of one of the
1354  * referenced function's arguments throws. Ignore the last parameter:
1355  * it is a dummy argument included to achieve conditional compilation
1356  * via SFINAE.
1357  * @return The result of the function call.
1358  *
1359  * Since 1.2.10
1360  */
1361 template <class Base, class Obj, class Ret, class Arg1, class Arg2>
1362 Ret fun(Obj& obj,
1363  Ret (*func)(Base*, Arg1, Arg2),
1364  typename Cgu::Param<Arg1>::ParamType arg1,
1365  typename Cgu::Param<Arg2>::ParamType arg2,
1366  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1367  return func(&obj, arg1, arg2);
1368 }
1369 
1370 /**
1371  * This function overload conditionally does nothing if the object
1372  * passed as the first argument does not relate to (ie it is not an
1373  * instance of nor derived from) the type to which the first argument
1374  * of the function to be conditionally executed is a pointer. This
1375  * function is thread safe if the return type's default constructor is
1376  * thread safe. It does not throw unless the return type's default
1377  * constructor throws. Ignore the last parameter: it is a dummy
1378  * argument included to achieve conditional compilation via SFINAE.
1379  * @return An empty object obtained by calling the return type's
1380  * default constructor.
1381  *
1382  * Since 1.2.10
1383  */
1384 template <class Base, class Obj, class Ret, class Arg1, class Arg2>
1385 Ret fun(Obj&,
1386  Ret (*)(Base*, Arg1, Arg2),
1387  typename Cgu::Param<Arg1>::ParamType,
1388  typename Cgu::Param<Arg2>::ParamType,
1389  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
1390  return Ret();
1391 }
1392 
1393 /* return value and one arg */
1394 /**
1395  * This function overload conditionally executes the function passed
1396  * as the second argument if the object passed as the first argument
1397  * relates to (ie is an instance of or derived from) the type to which
1398  * the first argument of the function to be conditionally executed is
1399  * a pointer. This function is thread safe if the referenced function
1400  * to be called is thread safe. It does not throw unless the
1401  * referenced function throws or (if its argument is not a built-in
1402  * type nor a reference argument) the copy constructor of the
1403  * referenced function's argument throws. Ignore the last parameter:
1404  * it is a dummy argument included to achieve conditional compilation
1405  * via SFINAE.
1406  * @return The result of the function call.
1407  *
1408  * Since 1.2.10
1409  */
1410 template <class Base, class Obj, class Ret, class Arg>
1411 Ret fun(Obj& obj,
1412  Ret (*func)(Base*, Arg),
1413  typename Cgu::Param<Arg>::ParamType arg,
1414  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1415  return func(&obj, arg);
1416 }
1417 
1418 /**
1419  * This function overload conditionally does nothing if the object
1420  * passed as the first argument does not relate to (ie it is not an
1421  * instance of nor derived from) the type to which the first argument
1422  * of the function to be conditionally executed is a pointer. This
1423  * function is thread safe if the return type's default constructor is
1424  * thread safe. It does not throw unless the return type's default
1425  * constructor throws. Ignore the last parameter: it is a dummy
1426  * argument included to achieve conditional compilation via SFINAE.
1427  * @return An empty object obtained by calling the return type's
1428  * default constructor.
1429  *
1430  * Since 1.2.10
1431  */
1432 template <class Base, class Obj, class Ret, class Arg>
1433 Ret fun(Obj&,
1434  Ret (*)(Base*, Arg),
1435  typename Cgu::Param<Arg>::ParamType,
1436  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
1437  return Ret();
1438 }
1439 
1440 /* return value and no arg */
1441 /**
1442  * This function overload conditionally executes the function passed
1443  * as the second argument if the object passed as the first argument
1444  * relates to (ie is an instance of or derived from) the type to which
1445  * the argument of the function to be conditionally executed is a
1446  * pointer. This function is thread safe if the referenced function
1447  * to be called is thread safe. It does not throw unless the
1448  * referenced function throws. Ignore the last parameter: it is a
1449  * dummy argument included to achieve conditional compilation via
1450  * SFINAE.
1451  * @return The result of the function call.
1452  *
1453  * Since 1.2.10
1454  */
1455 template <class Base, class Obj, class Ret>
1456 Ret fun(Obj& obj,
1457  Ret (*func)(Base*),
1458  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1459  return func(&obj);
1460 }
1461 
1462 /**
1463  * This function overload conditionally does nothing if the object
1464  * passed as the first argument does not relate to (ie it is not an
1465  * instance of nor derived from) the type to which the argument of the
1466  * function to be conditionally executed is a pointer. This function
1467  * is thread safe if the return type's default constructor is thread
1468  * safe. It does not throw unless the return type's default
1469  * constructor throws. Ignore the last parameter: it is a dummy
1470  * argument included to achieve conditional compilation via SFINAE.
1471  * @return An empty object obtained by calling the return type's
1472  * default constructor.
1473  *
1474  * Since 1.2.10
1475  */
1476 template <class Base, class Obj, class Ret>
1477 Ret fun(Obj&,
1478  Ret (*)(Base*),
1479  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {
1480  return Ret();
1481 }
1482 
1483 /* no return value and two args */
1484 /**
1485  * This function overload conditionally executes the function passed
1486  * as the second argument if the object passed as the first argument
1487  * relates to (ie is an instance of or derived from) the type to which
1488  * the first argument of the function to be conditionally executed is
1489  * a pointer. This function is thread safe if the referenced function
1490  * to be called is thread safe. It does not throw unless the
1491  * referenced function throws or (if its arguments are not built-in
1492  * types nor reference arguments) the copy constructor of one of the
1493  * referenced function's arguments throws. Ignore the last parameter:
1494  * it is a dummy argument included to achieve conditional compilation
1495  * via SFINAE.
1496  *
1497  * Since 1.2.10
1498  */
1499 template <class Base, class Obj, class Arg1, class Arg2>
1500 void fun(Obj& obj,
1501  void (*func)(Base*, Arg1, Arg2),
1502  typename Cgu::Param<Arg1>::ParamType arg1,
1503  typename Cgu::Param<Arg2>::ParamType arg2,
1504  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1505  func(&obj, arg1, arg2);
1506 }
1507 
1508 /**
1509  * This function overload conditionally does nothing if the object
1510  * passed as the first argument does not relate to (ie it is not an
1511  * instance of nor derived from) the type to which the first argument
1512  * of the function to be conditionally executed is a pointer. This
1513  * function is thread safe. It does not throw. Ignore the last
1514  * parameter: it is a dummy argument included to achieve conditional
1515  * compilation via SFINAE.
1516  *
1517  * Since 1.2.10
1518  */
1519 template <class Base, class Obj, class Arg1, class Arg2>
1520 void fun(Obj&,
1521  void (*)(Base*, Arg1, Arg2),
1522  typename Cgu::Param<Arg1>::ParamType,
1523  typename Cgu::Param<Arg2>::ParamType,
1524  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1525 
1526 /* no return value and one arg */
1527 /**
1528  * This function overload conditionally executes the function passed
1529  * as the second argument if the object passed as the first argument
1530  * relates to (ie is an instance of or derived from) the type to which
1531  * the first argument of the function to be conditionally executed is
1532  * a pointer. This function is thread safe if the referenced function
1533  * to be called is thread safe. It does not throw unless the
1534  * referenced function throws or (if its argument is not a built-in
1535  * type nor a reference argument) the copy constructor of the
1536  * referenced function's argument throws. Ignore the last parameter:
1537  * it is a dummy argument included to achieve conditional compilation
1538  * via SFINAE.
1539  *
1540  * Since 1.2.10
1541  */
1542 template <class Base, class Obj, class Arg>
1543 void fun(Obj& obj,
1544  void (*func)(Base*, Arg),
1545  typename Cgu::Param<Arg>::ParamType arg,
1546  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1547  func(&obj, arg);
1548 }
1549 
1550 /**
1551  * This function overload conditionally does nothing if the object
1552  * passed as the first argument does not relate to (ie it is not an
1553  * instance of nor derived from) the type to which the first argument
1554  * of the function to be conditionally executed is a pointer. This
1555  * function is thread safe. It does not throw. Ignore the last
1556  * parameter: it is a dummy argument included to achieve conditional
1557  * compilation via SFINAE.
1558  *
1559  * Since 1.2.10
1560  */
1561 template <class Base, class Obj, class Arg>
1562 void fun(Obj&,
1563  void (*)(Base*, Arg),
1564  typename Cgu::Param<Arg>::ParamType,
1565  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1566 
1567 /* no return value and no arg */
1568 /**
1569  * This function overload conditionally executes the function passed
1570  * as the second argument if the object passed as the first argument
1571  * relates to (ie is an instance of or derived from) the type to which
1572  * the argument of the function to be conditionally executed is a
1573  * pointer. This function is thread safe if the referenced function
1574  * to be called is thread safe. It does not throw unless the
1575  * referenced function throws. Ignore the last parameter: it is a
1576  * dummy argument included to achieve conditional compilation via
1577  * SFINAE.
1578  *
1579  * Since 1.2.10
1580  */
1581 template <class Base, class Obj>
1582 void fun(Obj& obj,
1583  void (*func)(Base*),
1584  typename SucceedOnTrue<RelatedTest<Base, Obj>::value>::T t = 0) {
1585  func(&obj);
1586 }
1587 
1588 /**
1589  * This function overload conditionally does nothing if the object
1590  * passed as the first argument does not relate to (ie it is not an
1591  * instance of nor derived from) the type to which the argument of the
1592  * function to be conditionally executed is a pointer. This function
1593  * is thread safe. It does not throw. Ignore the last parameter: it
1594  * is a dummy argument included to achieve conditional compilation via
1595  * SFINAE.
1596  *
1597  * Since 1.2.10
1598  */
1599 template <class Base, class Obj>
1600 void fun(Obj&,
1601  void (*)(Base*),
1602  typename SucceedOnFalse<RelatedTest<Base, Obj>::value>::T t = 0) {}
1603 
1604 } // namespace DoIf
1605 
1606 } // namespace Cgu
1607 
1608 #endif /* CGU_DO_IF */
Cgu::Param
Struct for automatic typing of parameter arguments for template functions.
Definition: param.h:79
Cgu::DoIf::assert_same_type
void assert_same_type(const T1 &t1, const T2 &t2)
Definition: do_if.h:712
Cgu
Definition: application.h:45
Cgu::DoIf::SucceedOnTrue< true >::T
void * T
Definition: do_if.h:826
Cgu::DoIf::RemoveConst
Class for removing a const qualifier.
Definition: do_if.h:616
Cgu::DoIf::RelatedTest::value
static const bool value
Definition: do_if.h:583
Cgu::DoIf::RelatedTest
Class for compile time testing of inheritance relationships.
Definition: do_if.h:553
Cgu::DoIf::StaticAssertion
Class for compile time assertion that a statement is true.
Definition: do_if.h:601
Cgu::DoIf::assert_related_types
void assert_related_types(const T1 &t1, const T2 &t2)
Definition: do_if.h:780
Cgu::DoIf::assert_not_const
void assert_not_const(T &t)
Definition: do_if.h:802
Cgu::DoIf::fun
Ret fun(Obj &obj, Ret(*func)(Base *, Arg1, Arg2), typename Cgu::Param< Arg1 >::ParamType arg1, typename Cgu::Param< Arg2 >::ParamType arg2, typename SucceedOnTrue< RelatedTest< Base, Obj >::value >::T t=0)
Definition: do_if.h:1362
param.h
Cgu::DoIf::RemoveConst< const T >::Type
T Type
Definition: do_if.h:622
Cgu::DoIf::RemoveConst::Type
T Type
Definition: do_if.h:617
Cgu::DoIf::mem_fun
Ret mem_fun(Obj &obj, Ret(Base::*func)(Arg1, Arg2), typename Cgu::Param< Arg1 >::ParamType arg1, typename Cgu::Param< Arg2 >::ParamType arg2, typename SucceedOnTrue< RelatedTest< Base, Obj >::value >::T t=0)
Definition: do_if.h:871
Cgu::DoIf::SucceedOnTrue
Struct which provides a type 'T' (typedef'ed to void*) if its template parameter is true.
Definition: do_if.h:822
Cgu::DoIf::SucceedOnFalse< false >::T
void * T
Definition: do_if.h:850
cgu_config.h
Cgu::DoIf::SucceedOnFalse
Struct which provides a type 'T' (typedef'ed to void*) if its template parameter is false.
Definition: do_if.h:846
Cgu::DoIf::assert_related_to_type
void assert_related_to_type(const Base &b, const Obj &o)
Definition: do_if.h:655