]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - sigc++/adaptors/macros/deduce_result_type.h.m4
Import libsigc++ 2.10.8 sources
[ext/sigc++-2.0.git] / sigc++ / adaptors / macros / deduce_result_type.h.m4
1 dnl Copyright 2002, The libsigc++ Development Team 
2 dnl 
3 dnl This library is free software; you can redistribute it and/or 
4 dnl modify it under the terms of the GNU Lesser General Public 
5 dnl License as published by the Free Software Foundation; either 
6 dnl version 2.1 of the License, or (at your option) any later version. 
7 dnl 
8 dnl This library is distributed in the hope that it will be useful, 
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
11 dnl Lesser General Public License for more details. 
12 dnl 
13 dnl You should have received a copy of the GNU Lesser General Public 
14 dnl License along with this library; if not, write to the Free Software 
15 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
16 dnl
17 divert(-1)
18 include(template.macros.m4)
19
20 divert(0)dnl
21 /*
22 */
23 _FIREWALL([ADAPTORS_DEDUCE_RESULT_TYPE])
24 #include <sigc++/functors/functor_trait.h>
25
26 namespace sigc {
27
28 /** A hint to the compiler.
29  * Functors which have all methods based on templates
30  * should publicly inherit from this hint and define 
31  * a nested template class @p deduce_result_type that
32  * can be used to deduce the methods' return types.
33  *
34  * adaptor_base inherits from the functor_base hint so
35  * derived types should also have a result_type defined.
36  *
37  * Adaptors don't inherit from this type directly. They use
38  * use sigc::adapts as a base type instead. sigc::adaptors
39  * wraps arbitrary functor types as well as function pointers
40  * and class methods.
41  *
42  * @ingroup adaptors
43  */
44 struct adaptor_base : public functor_base {};
45
46
47 /** Deduce the return type of a functor.
48  * <tt>typename deduce_result_type<functor_type, [list of arg_types]>::type</tt>
49  * deduces a functor's result type if @p functor_type inherits from
50  * sigc::functor_base and defines @p result_type or if @p functor_type
51  * is actually a (member) function type. Multi-type functors are not
52  * supported.
53  *
54  * sigc++ adaptors use
55  * <tt>typename deduce_result_type<functor_type, [list of arg_types]>::type</tt>
56  * to determine the return type of their <tt>templated operator()</tt> overloads.
57  *
58  * Adaptors in turn define a nested template class @p deduce_result_type
59  * that is used by template specializations of the global deduce_result_type
60  * template to correctly deduce the return types of the adaptor's suitable
61  * <tt>template operator()</tt> overload.
62  *
63  * @ingroup adaptors
64  */
65 template<class T_functor, class... T_args>
66 struct deduce_result_type
67 {
68   //The compiler will choose this method overload if T_functor derives from adaptor_base,
69   //and if it has its own deduce_result_type member (which has its own ::type member).
70   template<class U_functor, typename = typename std::is_base_of<adaptor_base, T_functor>::type>
71   static
72   typename U_functor::template deduce_result_type<T_args...>::type
73   test();
74
75   //Otherwise, the compiler will choose this fallback method.
76   template<class U_functor>
77   static
78   typename functor_trait<T_functor>::result_type
79   test();
80
81   using type = decltype (test<T_functor> ());
82 };
83
84 template<typename T_functor, typename... T_args>
85 using deduce_result_t = typename deduce_result_type<T_functor, T_args...>::type;
86
87 dnl #ifdef SIGC_CXX_TYPEOF
88 dnl FOR(0,CALL_SIZE,[[DEDUCE_RESULT_TYPE_TYPEOF(%1,CALL_SIZE)]])
89 dnl #endif
90 dnl
91 } /* namespace sigc */