numeric_op.hpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #if !defined(BOOST_PP_IS_ITERATING)
  2. ///// header body
  3. // NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION!
  4. // Copyright Aleksey Gurtovoy 2000-2004
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. #if !defined(BOOST_MPL_PREPROCESSING_MODE)
  15. # include <boost/mpl/numeric_cast.hpp>
  16. # include <boost/mpl/apply_wrap.hpp>
  17. # include <boost/mpl/if.hpp>
  18. # include <boost/mpl/tag.hpp>
  19. # include <boost/mpl/aux_/numeric_cast_utils.hpp>
  20. # include <boost/mpl/aux_/na.hpp>
  21. # include <boost/mpl/aux_/na_spec.hpp>
  22. # include <boost/mpl/aux_/lambda_support.hpp>
  23. # include <boost/mpl/aux_/msvc_eti_base.hpp>
  24. # include <boost/mpl/aux_/value_wknd.hpp>
  25. # include <boost/mpl/aux_/config/eti.hpp>
  26. # include <boost/mpl/aux_/nttp_decl.hpp>
  27. #endif
  28. #include <boost/mpl/aux_/config/static_constant.hpp>
  29. #if defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
  30. || defined(BOOST_MPL_PREPROCESSING_MODE)
  31. # include <boost/mpl/limits/arity.hpp>
  32. # include <boost/mpl/aux_/preprocessor/partial_spec_params.hpp>
  33. # include <boost/mpl/aux_/preprocessor/def_params_tail.hpp>
  34. # include <boost/mpl/aux_/preprocessor/repeat.hpp>
  35. # include <boost/mpl/aux_/preprocessor/ext_params.hpp>
  36. # include <boost/mpl/aux_/preprocessor/params.hpp>
  37. # include <boost/mpl/aux_/preprocessor/enum.hpp>
  38. # include <boost/mpl/aux_/preprocessor/add.hpp>
  39. # include <boost/mpl/aux_/preprocessor/sub.hpp>
  40. # include <boost/mpl/aux_/config/ctps.hpp>
  41. # include <boost/mpl/aux_/config/eti.hpp>
  42. # include <boost/mpl/aux_/config/msvc.hpp>
  43. # include <boost/mpl/aux_/config/workaround.hpp>
  44. # include <boost/preprocessor/dec.hpp>
  45. # include <boost/preprocessor/inc.hpp>
  46. # include <boost/preprocessor/iterate.hpp>
  47. # include <boost/preprocessor/cat.hpp>
  48. #if !defined(AUX778076_OP_ARITY)
  49. # define AUX778076_OP_ARITY BOOST_MPL_LIMIT_METAFUNCTION_ARITY
  50. #endif
  51. #if !defined(AUX778076_OP_IMPL_NAME)
  52. # define AUX778076_OP_IMPL_NAME BOOST_PP_CAT(AUX778076_OP_PREFIX,_impl)
  53. #endif
  54. #if !defined(AUX778076_OP_TAG_NAME)
  55. # define AUX778076_OP_TAG_NAME BOOST_PP_CAT(AUX778076_OP_PREFIX,_tag)
  56. #endif
  57. namespace boost { namespace mpl {
  58. template<
  59. typename Tag1
  60. , typename Tag2
  61. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  62. , BOOST_MPL_AUX_NTTP_DECL(int, tag1_) = BOOST_MPL_AUX_MSVC_VALUE_WKND(Tag1)::value
  63. , BOOST_MPL_AUX_NTTP_DECL(int, tag2_) = BOOST_MPL_AUX_MSVC_VALUE_WKND(Tag2)::value
  64. >
  65. struct AUX778076_OP_IMPL_NAME
  66. : if_c<
  67. ( tag1_ > tag2_ )
  68. #else
  69. >
  70. struct AUX778076_OP_IMPL_NAME
  71. : if_c<
  72. ( BOOST_MPL_AUX_NESTED_VALUE_WKND(int, Tag1)
  73. > BOOST_MPL_AUX_NESTED_VALUE_WKND(int, Tag2)
  74. )
  75. #endif
  76. , aux::cast2nd_impl< AUX778076_OP_IMPL_NAME<Tag1,Tag1>,Tag1,Tag2 >
  77. , aux::cast1st_impl< AUX778076_OP_IMPL_NAME<Tag2,Tag2>,Tag1,Tag2 >
  78. >::type
  79. {
  80. };
  81. /// for Digital Mars C++/compilers with no CTPS/TTP support
  82. template<> struct AUX778076_OP_IMPL_NAME<na,na>
  83. {
  84. template< typename U1, typename U2 > struct apply
  85. {
  86. typedef apply type;
  87. BOOST_STATIC_CONSTANT(int, value = 0);
  88. };
  89. };
  90. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  91. template< typename Tag > struct AUX778076_OP_IMPL_NAME<na,Tag>
  92. {
  93. template< typename U1, typename U2 > struct apply
  94. {
  95. typedef apply type;
  96. BOOST_STATIC_CONSTANT(int, value = 0);
  97. };
  98. };
  99. template< typename Tag > struct AUX778076_OP_IMPL_NAME<Tag,na>
  100. {
  101. template< typename U1, typename U2 > struct apply
  102. {
  103. typedef apply type;
  104. BOOST_STATIC_CONSTANT(int, value = 0);
  105. };
  106. };
  107. #else
  108. template<> struct AUX778076_OP_IMPL_NAME<na,integral_c_tag>
  109. {
  110. template< typename U1, typename U2 > struct apply
  111. {
  112. typedef apply type;
  113. BOOST_STATIC_CONSTANT(int, value = 0);
  114. };
  115. };
  116. template<> struct AUX778076_OP_IMPL_NAME<integral_c_tag,na>
  117. {
  118. template< typename U1, typename U2 > struct apply
  119. {
  120. typedef apply type;
  121. BOOST_STATIC_CONSTANT(int, value = 0);
  122. };
  123. };
  124. #endif
  125. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
  126. && BOOST_WORKAROUND(BOOST_MSVC, >= 1300)
  127. template< typename T > struct AUX778076_OP_TAG_NAME
  128. : tag<T,na>
  129. {
  130. };
  131. #else
  132. template< typename T > struct AUX778076_OP_TAG_NAME
  133. {
  134. typedef typename T::tag type;
  135. };
  136. #endif
  137. #if AUX778076_OP_ARITY != 2
  138. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  139. # define AUX778076_OP_RIGHT_OPERAND(unused, i, N) , BOOST_PP_CAT(N, BOOST_MPL_PP_ADD(i, 2))>
  140. # define AUX778076_OP_N_CALLS(i, N) \
  141. BOOST_MPL_PP_REPEAT( BOOST_PP_DEC(i), BOOST_MPL_PP_REPEAT_IDENTITY_FUNC, AUX778076_OP_NAME< ) \
  142. N1 BOOST_MPL_PP_REPEAT( BOOST_MPL_PP_SUB(i, 1), AUX778076_OP_RIGHT_OPERAND, N ) \
  143. /**/
  144. template<
  145. typename BOOST_MPL_AUX_NA_PARAM(N1)
  146. , typename BOOST_MPL_AUX_NA_PARAM(N2)
  147. BOOST_MPL_PP_DEF_PARAMS_TAIL(2, typename N, na)
  148. >
  149. struct AUX778076_OP_NAME
  150. : AUX778076_OP_N_CALLS(AUX778076_OP_ARITY, N)
  151. {
  152. BOOST_MPL_AUX_LAMBDA_SUPPORT(
  153. AUX778076_OP_ARITY
  154. , AUX778076_OP_NAME
  155. , ( BOOST_MPL_PP_PARAMS(AUX778076_OP_ARITY, N) )
  156. )
  157. };
  158. #define BOOST_PP_ITERATION_PARAMS_1 \
  159. (3,( BOOST_PP_DEC(AUX778076_OP_ARITY), 2, <boost/mpl/aux_/numeric_op.hpp> ))
  160. #include BOOST_PP_ITERATE()
  161. # undef AUX778076_OP_N_CALLS
  162. # undef AUX778076_OP_RIGHT_OPERAND
  163. # else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  164. /// forward declaration
  165. template<
  166. typename BOOST_MPL_AUX_NA_PARAM(N1)
  167. , typename BOOST_MPL_AUX_NA_PARAM(N2)
  168. >
  169. struct BOOST_PP_CAT(AUX778076_OP_NAME,2);
  170. template<
  171. typename BOOST_MPL_AUX_NA_PARAM(N1)
  172. , typename BOOST_MPL_AUX_NA_PARAM(N2)
  173. BOOST_MPL_PP_DEF_PARAMS_TAIL(2, typename N, na)
  174. >
  175. struct AUX778076_OP_NAME
  176. #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
  177. : aux::msvc_eti_base< typename if_<
  178. #else
  179. : if_<
  180. #endif
  181. is_na<N3>
  182. , BOOST_PP_CAT(AUX778076_OP_NAME,2)<N1,N2>
  183. , AUX778076_OP_NAME<
  184. BOOST_PP_CAT(AUX778076_OP_NAME,2)<N1,N2>
  185. , BOOST_MPL_PP_EXT_PARAMS(3, BOOST_PP_INC(AUX778076_OP_ARITY), N)
  186. >
  187. >::type
  188. #if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
  189. >
  190. #endif
  191. {
  192. BOOST_MPL_AUX_LAMBDA_SUPPORT(
  193. AUX778076_OP_ARITY
  194. , AUX778076_OP_NAME
  195. , ( BOOST_MPL_PP_PARAMS(AUX778076_OP_ARITY, N) )
  196. )
  197. };
  198. template<
  199. typename N1
  200. , typename N2
  201. >
  202. struct BOOST_PP_CAT(AUX778076_OP_NAME,2)
  203. #endif
  204. #else // AUX778076_OP_ARITY == 2
  205. template<
  206. typename BOOST_MPL_AUX_NA_PARAM(N1)
  207. , typename BOOST_MPL_AUX_NA_PARAM(N2)
  208. >
  209. struct AUX778076_OP_NAME
  210. #endif
  211. #if !defined(BOOST_MPL_CFG_MSVC_ETI_BUG)
  212. : AUX778076_OP_IMPL_NAME<
  213. typename AUX778076_OP_TAG_NAME<N1>::type
  214. , typename AUX778076_OP_TAG_NAME<N2>::type
  215. >::template apply<N1,N2>::type
  216. #else
  217. : aux::msvc_eti_base< typename apply_wrap2<
  218. AUX778076_OP_IMPL_NAME<
  219. typename AUX778076_OP_TAG_NAME<N1>::type
  220. , typename AUX778076_OP_TAG_NAME<N2>::type
  221. >
  222. , N1
  223. , N2
  224. >::type >::type
  225. #endif
  226. {
  227. #if AUX778076_OP_ARITY != 2
  228. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  229. BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(
  230. AUX778076_OP_ARITY
  231. , AUX778076_OP_NAME
  232. , ( BOOST_MPL_PP_PARTIAL_SPEC_PARAMS(2, N, na) )
  233. )
  234. # else
  235. BOOST_MPL_AUX_LAMBDA_SUPPORT(2, BOOST_PP_CAT(AUX778076_OP_NAME,2), (N1, N2))
  236. # endif
  237. #else
  238. BOOST_MPL_AUX_LAMBDA_SUPPORT(2, AUX778076_OP_NAME, (N1, N2))
  239. #endif
  240. };
  241. BOOST_MPL_AUX_NA_SPEC2(2, AUX778076_OP_ARITY, AUX778076_OP_NAME)
  242. }}
  243. #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  244. ///// iteration, depth == 1
  245. // For gcc 4.4 compatability, we must include the
  246. // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
  247. #else // BOOST_PP_IS_ITERATING
  248. #if BOOST_PP_ITERATION_DEPTH() == 1
  249. # define i_ BOOST_PP_FRAME_ITERATION(1)
  250. template<
  251. BOOST_MPL_PP_PARAMS(i_, typename N)
  252. >
  253. struct AUX778076_OP_NAME<BOOST_MPL_PP_PARTIAL_SPEC_PARAMS(i_, N, na)>
  254. #if i_ != 2
  255. : AUX778076_OP_N_CALLS(i_, N)
  256. {
  257. BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(
  258. AUX778076_OP_ARITY
  259. , AUX778076_OP_NAME
  260. , ( BOOST_MPL_PP_PARTIAL_SPEC_PARAMS(i_, N, na) )
  261. )
  262. };
  263. #endif
  264. # undef i_
  265. #endif // BOOST_PP_ITERATION_DEPTH()
  266. #endif // BOOST_PP_IS_ITERATING