]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - untracked/sigc++/adaptors/deduce_result_type.h
Import libsigc++ 2.10.8 sources
[ext/sigc++-2.0.git] / untracked / sigc++ / adaptors / deduce_result_type.h
1 // -*- c++ -*-
2 /* Do not edit! -- generated file */
3 /*
4 */
5 #ifndef _SIGC_ADAPTORS_DEDUCE_RESULT_TYPE_H_
6 #define _SIGC_ADAPTORS_DEDUCE_RESULT_TYPE_H_
7 #include <sigc++/functors/functor_trait.h>
8
9 namespace sigc {
10
11 /** A hint to the compiler.
12  * Functors which have all methods based on templates
13  * should publicly inherit from this hint and define 
14  * a nested template class @p deduce_result_type that
15  * can be used to deduce the methods' return types.
16  *
17  * adaptor_base inherits from the functor_base hint so
18  * derived types should also have a result_type defined.
19  *
20  * Adaptors don't inherit from this type directly. They use
21  * use sigc::adapts as a base type instead. sigc::adaptors
22  * wraps arbitrary functor types as well as function pointers
23  * and class methods.
24  *
25  * @ingroup adaptors
26  */
27 struct adaptor_base : public functor_base {};
28
29
30 /** Deduce the return type of a functor.
31  * <tt>typename deduce_result_type<functor_type, list of arg_types>::type</tt>
32  * deduces a functor's result type if @p functor_type inherits from
33  * sigc::functor_base and defines @p result_type or if @p functor_type
34  * is actually a (member) function type. Multi-type functors are not
35  * supported.
36  *
37  * sigc++ adaptors use
38  * <tt>typename deduce_result_type<functor_type, list of arg_types>::type</tt>
39  * to determine the return type of their <tt>templated operator()</tt> overloads.
40  *
41  * Adaptors in turn define a nested template class @p deduce_result_type
42  * that is used by template specializations of the global deduce_result_type
43  * template to correctly deduce the return types of the adaptor's suitable
44  * <tt>template operator()</tt> overload.
45  *
46  * @ingroup adaptors
47  */
48 template<class T_functor, class... T_args>
49 struct deduce_result_type
50 {
51   //The compiler will choose this method overload if T_functor derives from adaptor_base,
52   //and if it has its own deduce_result_type member (which has its own ::type member).
53   template<class U_functor, typename = typename std::is_base_of<adaptor_base, T_functor>::type>
54   static
55   typename U_functor::template deduce_result_type<T_args...>::type
56   test();
57
58   //Otherwise, the compiler will choose this fallback method.
59   template<class U_functor>
60   static
61   typename functor_trait<T_functor>::result_type
62   test();
63
64   using type = decltype (test<T_functor> ());
65 };
66
67 template<typename T_functor, typename... T_args>
68 using deduce_result_t = typename deduce_result_type<T_functor, T_args...>::type;
69
70 } /* namespace sigc */
71 #endif /* _SIGC_ADAPTORS_DEDUCE_RESULT_TYPE_H_ */