1 | // Boost result_of library |
---|
2 | |
---|
3 | // Copyright Douglas Gregor 2004. Use, modification and |
---|
4 | // distribution is subject to the Boost Software License, Version |
---|
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
6 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | |
---|
8 | // For more information, see http://www.boost.org/libs/utility |
---|
9 | #ifndef BOOST_RESULT_OF_HPP |
---|
10 | #define BOOST_RESULT_OF_HPP |
---|
11 | |
---|
12 | #include <boost/config.hpp> |
---|
13 | #include <boost/preprocessor/iteration/iterate.hpp> |
---|
14 | #include <boost/preprocessor/punctuation/comma_if.hpp> |
---|
15 | #include <boost/preprocessor/repetition/enum_params.hpp> |
---|
16 | #include <boost/preprocessor/repetition/enum_shifted_params.hpp> |
---|
17 | #include <boost/detail/workaround.hpp> |
---|
18 | #include <boost/mpl/has_xxx.hpp> |
---|
19 | #include <boost/mpl/if.hpp> |
---|
20 | #include <boost/mpl/bool.hpp> |
---|
21 | #include <boost/mpl/or.hpp> |
---|
22 | #include <boost/type_traits/is_pointer.hpp> |
---|
23 | #include <boost/type_traits/is_member_function_pointer.hpp> |
---|
24 | #include <boost/type_traits/remove_cv.hpp> |
---|
25 | |
---|
26 | #ifndef BOOST_RESULT_OF_NUM_ARGS |
---|
27 | # define BOOST_RESULT_OF_NUM_ARGS 10 |
---|
28 | #endif |
---|
29 | |
---|
30 | namespace boost { |
---|
31 | |
---|
32 | template<typename F> struct result_of; |
---|
33 | template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of |
---|
34 | |
---|
35 | #if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
---|
36 | namespace detail { |
---|
37 | |
---|
38 | BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) |
---|
39 | |
---|
40 | template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl; |
---|
41 | template<typename F> struct cpp0x_result_of_impl; |
---|
42 | |
---|
43 | template<typename F> |
---|
44 | struct result_of_void_impl |
---|
45 | { |
---|
46 | typedef void type; |
---|
47 | }; |
---|
48 | |
---|
49 | template<typename R> |
---|
50 | struct result_of_void_impl<R (*)(void)> |
---|
51 | { |
---|
52 | typedef R type; |
---|
53 | }; |
---|
54 | |
---|
55 | template<typename R> |
---|
56 | struct result_of_void_impl<R (&)(void)> |
---|
57 | { |
---|
58 | typedef R type; |
---|
59 | }; |
---|
60 | |
---|
61 | // Determine the return type of a function pointer or pointer to member. |
---|
62 | template<typename F, typename FArgs> |
---|
63 | struct result_of_pointer |
---|
64 | : tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { }; |
---|
65 | |
---|
66 | template<typename F, typename FArgs> |
---|
67 | struct tr1_result_of_impl<F, FArgs, true> |
---|
68 | { |
---|
69 | typedef typename F::result_type type; |
---|
70 | }; |
---|
71 | |
---|
72 | template<typename FArgs> |
---|
73 | struct is_function_with_no_args : mpl::false_ {}; |
---|
74 | |
---|
75 | template<typename F> |
---|
76 | struct is_function_with_no_args<F(void)> : mpl::true_ {}; |
---|
77 | |
---|
78 | template<typename F, typename FArgs> |
---|
79 | struct result_of_nested_result : F::template result<FArgs> |
---|
80 | {}; |
---|
81 | |
---|
82 | template<typename F, typename FArgs> |
---|
83 | struct tr1_result_of_impl<F, FArgs, false> |
---|
84 | : mpl::if_<is_function_with_no_args<FArgs>, |
---|
85 | result_of_void_impl<F>, |
---|
86 | result_of_nested_result<F, FArgs> >::type |
---|
87 | {}; |
---|
88 | |
---|
89 | } // end namespace detail |
---|
90 | |
---|
91 | #define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,<boost/utility/detail/result_of_iterate.hpp>)) |
---|
92 | #include BOOST_PP_ITERATE() |
---|
93 | |
---|
94 | #else |
---|
95 | # define BOOST_NO_RESULT_OF 1 |
---|
96 | #endif |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | #endif // BOOST_RESULT_OF_HPP |
---|