1 dnl Copyright 2002, The libsigc++ Development Team
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.
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.
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
18 include(template.macros.m4)
23 _FIREWALL([ADAPTORS_DEDUCE_RESULT_TYPE])
24 #include <sigc++/functors/functor_trait.h>
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.
34 * adaptor_base inherits from the functor_base hint so
35 * derived types should also have a result_type defined.
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
44 struct adaptor_base : public functor_base {};
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
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.
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.
65 template<class T_functor, class... T_args>
66 struct deduce_result_type
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>
72 typename U_functor::template deduce_result_type<T_args...>::type
75 //Otherwise, the compiler will choose this fallback method.
76 template<class U_functor>
78 typename functor_trait<T_functor>::result_type
81 using type = decltype (test<T_functor> ());
84 template<typename T_functor, typename... T_args>
85 using deduce_result_t = typename deduce_result_type<T_functor, T_args...>::type;
87 dnl #ifdef SIGC_CXX_TYPEOF
88 dnl FOR(0,CALL_SIZE,[[DEDUCE_RESULT_TYPE_TYPEOF(%1,CALL_SIZE)]])
91 } /* namespace sigc */