2 // Copyright (C) 2009-2012 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0
4 // (see accompanying file LICENSE_1_0.txt or a copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // Home at http://www.boost.org/libs/functional/overloaded_function
8 #ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_FUNCTION_TYPE_HPP_
9 #define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_FUNCTION_TYPE_HPP_
11 #include <boost/function_types/is_function.hpp>
12 #include <boost/function_types/is_function_pointer.hpp>
13 #include <boost/function_types/is_function_reference.hpp>
14 #include <boost/function_types/function_type.hpp>
15 #include <boost/function_types/parameter_types.hpp>
16 #include <boost/function_types/result_type.hpp>
17 #include <boost/type_traits/remove_pointer.hpp>
18 #include <boost/type_traits/remove_reference.hpp>
19 #include <boost/function.hpp>
20 #include <boost/mpl/if.hpp>
21 #include <boost/mpl/identity.hpp>
22 #include <boost/mpl/pop_front.hpp>
23 #include <boost/mpl/push_front.hpp>
24 #include <boost/typeof/typeof.hpp>
26 // Do not use namespace ::detail because overloaded_function is already a class.
27 namespace boost { namespace overloaded_function_detail {
29 // Requires: F is a monomorphic functor (i.e., has non-template `operator()`).
30 // Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
31 // It does not assume F typedef result_type, arg1_type, ... but needs typeof.
34 // NOTE: clang does not accept extra parenthesis `&(...)`.
35 typedef BOOST_TYPEOF_TPL(&F::operator()) call_ptr;
38 typename boost::function_types::function_type<
39 typename boost::mpl::push_front<
40 typename boost::mpl::pop_front< // Remove functor type (1st).
41 typename boost::function_types::parameter_types<
44 , typename boost::function_types::result_type<call_ptr>::type
50 // NOTE: When using boost::function in Boost.Typeof emulation mode, the user
51 // has to register boost::functionN instead of boost::function in oder to
52 // do TYPEOF(F::operator()). That is confusing, so boost::function is handled
53 // separately so it does not require any Boost.Typeof registration at all.
55 struct functor_type< boost::function<F> > {
59 // Requires: F is a function type, pointer, reference, or monomorphic functor.
60 // Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
62 struct function_type {
64 typename boost::mpl::if_<boost::function_types::is_function<F>,
65 boost::mpl::identity<F>
67 typename boost::mpl::if_<boost::function_types::
68 is_function_pointer<F>,
69 boost::remove_pointer<F>
71 typename boost::mpl::if_<boost::function_types::
72 is_function_reference<F>,
73 boost::remove_reference<F>
74 , // Else, requires that F is a functor.
84 #endif // #include guard