result_of_iterate.hpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // Boost result_of library
  2. // Copyright Douglas Gregor 2004. Use, modification and
  3. // distribution is subject to the Boost Software License, Version
  4. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // Copyright Daniel Walker, Eric Niebler, Michel Morin 2008-2012.
  7. // Use, modification and distribution is subject to the Boost Software
  8. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or
  9. // copy at http://www.boost.org/LICENSE_1_0.txt)
  10. // For more information, see http://www.boost.org/libs/utility
  11. #if !defined(BOOST_PP_IS_ITERATING)
  12. # error Boost result_of - do not include this file!
  13. #endif
  14. // CWPro8 requires an argument in a function type specialization
  15. #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0
  16. # define BOOST_RESULT_OF_ARGS void
  17. #else
  18. # define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)
  19. #endif
  20. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
  21. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  22. struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)>
  23. : conditional<
  24. is_pointer<F>::value || is_member_function_pointer<F>::value
  25. , boost::detail::tr1_result_of_impl<
  26. typename remove_cv<F>::type,
  27. typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS),
  28. (boost::detail::result_of_has_result_type<F>::value)>
  29. , boost::detail::tr1_result_of_impl<
  30. F,
  31. F(BOOST_RESULT_OF_ARGS),
  32. (boost::detail::result_of_has_result_type<F>::value)> >::type { };
  33. #endif
  34. #ifdef BOOST_RESULT_OF_USE_DECLTYPE
  35. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  36. struct result_of<F(BOOST_RESULT_OF_ARGS)>
  37. : detail::cpp0x_result_of<F(BOOST_RESULT_OF_ARGS)> { };
  38. #endif // BOOST_RESULT_OF_USE_DECLTYPE
  39. #ifdef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
  40. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  41. struct result_of<F(BOOST_RESULT_OF_ARGS)>
  42. : conditional<detail::result_of_has_result_type<F>::value || detail::result_of_has_result<F>::value,
  43. tr1_result_of<F(BOOST_RESULT_OF_ARGS)>,
  44. detail::cpp0x_result_of<F(BOOST_RESULT_OF_ARGS)> >::type { };
  45. #endif // BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
  46. #if defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)
  47. namespace detail {
  48. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  49. struct cpp0x_result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
  50. : conditional<
  51. is_member_function_pointer<F>::value
  52. , detail::tr1_result_of_impl<
  53. typename remove_cv<F>::type,
  54. typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false
  55. >
  56. , detail::cpp0x_result_of_impl<
  57. F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))
  58. >
  59. >::type
  60. {};
  61. #ifdef BOOST_NO_SFINAE_EXPR
  62. template<typename F>
  63. struct BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION());
  64. template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), typename T)>
  65. struct BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<R(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T))> {
  66. R operator()(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T)) const;
  67. typedef result_of_private_type const &(*pfn_t)(...);
  68. operator pfn_t() const volatile;
  69. };
  70. template<typename F>
  71. struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())
  72. : BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<F>
  73. {};
  74. template<typename F>
  75. struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<F *>
  76. : BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<F>
  77. {};
  78. template<typename F>
  79. struct BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION())
  80. : conditional<
  81. is_class<typename remove_reference<F>::type>::value,
  82. result_of_wrap_callable_class<F>,
  83. type_identity<BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<typename remove_cv<typename remove_reference<F>::type>::type> >
  84. >::type
  85. {};
  86. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), typename T)>
  87. struct BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION()) {
  88. typedef typename BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION())<F>::type wrapper_t;
  89. static const bool value = (
  90. sizeof(result_of_no_type) == sizeof(detail::result_of_is_private_type(
  91. (boost::declval<wrapper_t>()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)), result_of_weird_type())
  92. ))
  93. );
  94. typedef integral_constant<bool, value> type;
  95. };
  96. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  97. struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), true>
  98. : lazy_enable_if<
  99. BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION())<F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), T)>
  100. , cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false>
  101. >
  102. {};
  103. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  104. struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false>
  105. {
  106. typedef decltype(
  107. boost::declval<F>()(
  108. BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)
  109. )
  110. ) type;
  111. };
  112. #else // BOOST_NO_SFINAE_EXPR
  113. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  114. struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)),
  115. typename result_of_always_void<decltype(
  116. boost::declval<F>()(
  117. BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)
  118. )
  119. )>::type> {
  120. typedef decltype(
  121. boost::declval<F>()(
  122. BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)
  123. )
  124. ) type;
  125. };
  126. #endif // BOOST_NO_SFINAE_EXPR
  127. } // namespace detail
  128. #else // defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)
  129. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
  130. template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  131. struct result_of<F(BOOST_RESULT_OF_ARGS)>
  132. : tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { };
  133. #endif
  134. #endif // defined(BOOST_RESULT_OF_USE_DECLTYPE)
  135. #undef BOOST_RESULT_OF_ARGS
  136. #if BOOST_PP_ITERATION() >= 1
  137. namespace detail {
  138. template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  139. struct tr1_result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
  140. {
  141. typedef R type;
  142. };
  143. template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  144. struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
  145. {
  146. typedef R type;
  147. };
  148. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
  149. template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  150. struct tr1_result_of_impl<R (T0::*)
  151. (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)),
  152. FArgs, false>
  153. {
  154. typedef R type;
  155. };
  156. template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  157. struct tr1_result_of_impl<R (T0::*)
  158. (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
  159. const,
  160. FArgs, false>
  161. {
  162. typedef R type;
  163. };
  164. template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  165. struct tr1_result_of_impl<R (T0::*)
  166. (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
  167. volatile,
  168. FArgs, false>
  169. {
  170. typedef R type;
  171. };
  172. template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
  173. struct tr1_result_of_impl<R (T0::*)
  174. (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
  175. const volatile,
  176. FArgs, false>
  177. {
  178. typedef R type;
  179. };
  180. #endif
  181. }
  182. #endif