Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 <ndnboost/config.hpp> |
| 13 | #include <ndnboost/preprocessor/cat.hpp> |
| 14 | #include <ndnboost/preprocessor/iteration/iterate.hpp> |
| 15 | #include <ndnboost/preprocessor/repetition/enum_params.hpp> |
| 16 | #include <ndnboost/preprocessor/repetition/enum_trailing_params.hpp> |
| 17 | #include <ndnboost/preprocessor/repetition/enum_binary_params.hpp> |
| 18 | #include <ndnboost/preprocessor/repetition/enum_shifted_params.hpp> |
| 19 | #include <ndnboost/preprocessor/facilities/intercept.hpp> |
| 20 | #include <ndnboost/detail/workaround.hpp> |
| 21 | #include <ndnboost/mpl/has_xxx.hpp> |
| 22 | #include <ndnboost/mpl/if.hpp> |
| 23 | #include <ndnboost/mpl/eval_if.hpp> |
| 24 | #include <ndnboost/mpl/bool.hpp> |
| 25 | #include <ndnboost/mpl/identity.hpp> |
| 26 | #include <ndnboost/mpl/or.hpp> |
| 27 | #include <ndnboost/type_traits/is_class.hpp> |
| 28 | #include <ndnboost/type_traits/is_pointer.hpp> |
| 29 | #include <ndnboost/type_traits/is_member_function_pointer.hpp> |
| 30 | #include <ndnboost/type_traits/remove_cv.hpp> |
| 31 | #include <ndnboost/type_traits/remove_reference.hpp> |
| 32 | #include <ndnboost/utility/declval.hpp> |
| 33 | #include <ndnboost/utility/enable_if.hpp> |
| 34 | |
| 35 | #ifndef BOOST_RESULT_OF_NUM_ARGS |
| 36 | # define BOOST_RESULT_OF_NUM_ARGS 16 |
| 37 | #endif |
| 38 | |
| 39 | // Use the decltype-based version of result_of by default if the compiler |
| 40 | // supports N3276 <http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3276.pdf>. |
| 41 | // The user can force the choice by defining either BOOST_RESULT_OF_USE_DECLTYPE or |
| 42 | // BOOST_RESULT_OF_USE_TR1, but not both! |
| 43 | #if defined(BOOST_RESULT_OF_USE_DECLTYPE) && defined(BOOST_RESULT_OF_USE_TR1) |
| 44 | # error Both BOOST_RESULT_OF_USE_DECLTYPE and BOOST_RESULT_OF_USE_TR1 cannot be defined at the same time. |
| 45 | #endif |
| 46 | |
| 47 | #ifndef BOOST_RESULT_OF_USE_TR1 |
| 48 | # ifndef BOOST_RESULT_OF_USE_DECLTYPE |
| 49 | # ifndef BOOST_NO_CXX11_DECLTYPE_N3276 // this implies !defined(BOOST_NO_CXX11_DECLTYPE) |
| 50 | # define BOOST_RESULT_OF_USE_DECLTYPE |
| 51 | # else |
| 52 | # define BOOST_RESULT_OF_USE_TR1 |
| 53 | # endif |
| 54 | # endif |
| 55 | #endif |
| 56 | |
| 57 | namespace ndnboost { |
| 58 | |
| 59 | template<typename F> struct result_of; |
| 60 | template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of |
| 61 | |
| 62 | #if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
| 63 | namespace detail { |
| 64 | |
| 65 | BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) |
| 66 | |
| 67 | template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl; |
| 68 | |
| 69 | #ifdef BOOST_NO_SFINAE_EXPR |
| 70 | |
| 71 | // There doesn't seem to be any other way to turn this off such that the presence of |
| 72 | // the user-defined operator,() below doesn't cause spurious warning all over the place, |
| 73 | // so unconditionally turn it off. |
| 74 | #if BOOST_MSVC |
| 75 | # pragma warning(disable: 4913) // user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used |
| 76 | #endif |
| 77 | |
| 78 | struct result_of_private_type {}; |
| 79 | |
| 80 | struct result_of_weird_type { |
| 81 | friend result_of_private_type operator,(result_of_private_type, result_of_weird_type); |
| 82 | }; |
| 83 | |
| 84 | typedef char result_of_yes_type; // sizeof(result_of_yes_type) == 1 |
| 85 | typedef char (&result_of_no_type)[2]; // sizeof(result_of_no_type) == 2 |
| 86 | |
| 87 | template<typename T> |
| 88 | result_of_no_type result_of_is_private_type(T const &); |
| 89 | result_of_yes_type result_of_is_private_type(result_of_private_type); |
| 90 | |
| 91 | template<typename C> |
| 92 | struct result_of_callable_class : C { |
| 93 | result_of_callable_class(); |
| 94 | typedef result_of_private_type const &(*pfn_t)(...); |
| 95 | operator pfn_t() const volatile; |
| 96 | }; |
| 97 | |
| 98 | template<typename C> |
| 99 | struct result_of_wrap_callable_class { |
| 100 | typedef result_of_callable_class<C> type; |
| 101 | }; |
| 102 | |
| 103 | template<typename C> |
| 104 | struct result_of_wrap_callable_class<C const> { |
| 105 | typedef result_of_callable_class<C> const type; |
| 106 | }; |
| 107 | |
| 108 | template<typename C> |
| 109 | struct result_of_wrap_callable_class<C volatile> { |
| 110 | typedef result_of_callable_class<C> volatile type; |
| 111 | }; |
| 112 | |
| 113 | template<typename C> |
| 114 | struct result_of_wrap_callable_class<C const volatile> { |
| 115 | typedef result_of_callable_class<C> const volatile type; |
| 116 | }; |
| 117 | |
| 118 | template<typename C> |
| 119 | struct result_of_wrap_callable_class<C &> { |
| 120 | typedef typename result_of_wrap_callable_class<C>::type &type; |
| 121 | }; |
| 122 | |
| 123 | template<typename F, bool TestCallability = true> struct cpp0x_result_of_impl; |
| 124 | |
| 125 | #else // BOOST_NO_SFINAE_EXPR |
| 126 | |
| 127 | template<typename T> |
| 128 | struct result_of_always_void |
| 129 | { |
| 130 | typedef void type; |
| 131 | }; |
| 132 | |
| 133 | template<typename F, typename Enable = void> struct cpp0x_result_of_impl {}; |
| 134 | |
| 135 | #endif // BOOST_NO_SFINAE_EXPR |
| 136 | |
| 137 | template<typename F> |
| 138 | struct result_of_void_impl |
| 139 | { |
| 140 | typedef void type; |
| 141 | }; |
| 142 | |
| 143 | template<typename R> |
| 144 | struct result_of_void_impl<R (*)(void)> |
| 145 | { |
| 146 | typedef R type; |
| 147 | }; |
| 148 | |
| 149 | template<typename R> |
| 150 | struct result_of_void_impl<R (&)(void)> |
| 151 | { |
| 152 | typedef R type; |
| 153 | }; |
| 154 | |
| 155 | // Determine the return type of a function pointer or pointer to member. |
| 156 | template<typename F, typename FArgs> |
| 157 | struct result_of_pointer |
| 158 | : tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { }; |
| 159 | |
| 160 | template<typename F, typename FArgs> |
| 161 | struct tr1_result_of_impl<F, FArgs, true> |
| 162 | { |
| 163 | typedef typename F::result_type type; |
| 164 | }; |
| 165 | |
| 166 | template<typename FArgs> |
| 167 | struct is_function_with_no_args : mpl::false_ {}; |
| 168 | |
| 169 | template<typename F> |
| 170 | struct is_function_with_no_args<F(void)> : mpl::true_ {}; |
| 171 | |
| 172 | template<typename F, typename FArgs> |
| 173 | struct result_of_nested_result : F::template result<FArgs> |
| 174 | {}; |
| 175 | |
| 176 | template<typename F, typename FArgs> |
| 177 | struct tr1_result_of_impl<F, FArgs, false> |
| 178 | : mpl::if_<is_function_with_no_args<FArgs>, |
| 179 | result_of_void_impl<F>, |
| 180 | result_of_nested_result<F, FArgs> >::type |
| 181 | {}; |
| 182 | |
| 183 | } // end namespace detail |
| 184 | |
| 185 | #define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,<ndnboost/utility/detail/result_of_iterate.hpp>)) |
| 186 | #include BOOST_PP_ITERATE() |
| 187 | |
| 188 | #else |
| 189 | # define BOOST_NO_RESULT_OF 1 |
| 190 | #endif |
| 191 | |
| 192 | } |
| 193 | |
| 194 | #endif // BOOST_RESULT_OF_HPP |