inserter_algorithm.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef BOOST_MPL_AUX_INSERTER_ALGORITHM_HPP_INCLUDED
  2. #define BOOST_MPL_AUX_INSERTER_ALGORITHM_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2003-2004
  4. // Copyright David Abrahams 2003-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. #include <boost/mpl/back_inserter.hpp>
  15. #include <boost/mpl/front_inserter.hpp>
  16. #include <boost/mpl/push_back.hpp>
  17. #include <boost/mpl/push_front.hpp>
  18. #include <boost/mpl/back_inserter.hpp>
  19. #include <boost/mpl/front_inserter.hpp>
  20. #include <boost/mpl/clear.hpp>
  21. #include <boost/mpl/eval_if.hpp>
  22. #include <boost/mpl/if.hpp>
  23. #include <boost/mpl/aux_/na.hpp>
  24. #include <boost/mpl/aux_/common_name_wknd.hpp>
  25. #include <boost/mpl/aux_/na_spec.hpp>
  26. #include <boost/mpl/aux_/preprocessor/params.hpp>
  27. #include <boost/mpl/aux_/preprocessor/default_params.hpp>
  28. #include <boost/mpl/aux_/config/ctps.hpp>
  29. #include <boost/preprocessor/arithmetic/dec.hpp>
  30. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  31. # define BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(arity, name) \
  32. BOOST_MPL_AUX_COMMON_NAME_WKND(name) \
  33. template< \
  34. BOOST_MPL_PP_DEFAULT_PARAMS(arity, typename P, na) \
  35. > \
  36. struct name \
  37. : aux::name##_impl<BOOST_MPL_PP_PARAMS(arity, P)> \
  38. { \
  39. }; \
  40. \
  41. template< \
  42. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), typename P) \
  43. > \
  44. struct name< BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P),na > \
  45. : if_< has_push_back< typename clear<P1>::type> \
  46. , aux::name##_impl< \
  47. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  48. , back_inserter< typename clear<P1>::type > \
  49. > \
  50. , aux::reverse_##name##_impl< \
  51. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  52. , front_inserter< typename clear<P1>::type > \
  53. > \
  54. >::type \
  55. { \
  56. }; \
  57. \
  58. template< \
  59. BOOST_MPL_PP_DEFAULT_PARAMS(arity, typename P, na) \
  60. > \
  61. struct reverse_##name \
  62. : aux::reverse_##name##_impl<BOOST_MPL_PP_PARAMS(arity, P)> \
  63. { \
  64. }; \
  65. \
  66. template< \
  67. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), typename P) \
  68. > \
  69. struct reverse_##name< BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P),na > \
  70. : if_< has_push_back<P1> \
  71. , aux::reverse_##name##_impl< \
  72. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  73. , back_inserter< typename clear<P1>::type > \
  74. > \
  75. , aux::name##_impl< \
  76. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  77. , front_inserter< typename clear<P1>::type > \
  78. > \
  79. >::type \
  80. { \
  81. }; \
  82. BOOST_MPL_AUX_NA_SPEC(arity, name) \
  83. BOOST_MPL_AUX_NA_SPEC(arity, reverse_##name) \
  84. /**/
  85. #else
  86. # define BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(arity, name) \
  87. BOOST_MPL_AUX_COMMON_NAME_WKND(name) \
  88. template< \
  89. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), typename P) \
  90. > \
  91. struct def_##name##_impl \
  92. : if_< has_push_back<P1> \
  93. , aux::name##_impl< \
  94. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  95. , back_inserter< typename clear<P1>::type > \
  96. > \
  97. , aux::reverse_##name##_impl< \
  98. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  99. , front_inserter< typename clear<P1>::type > \
  100. > \
  101. >::type \
  102. { \
  103. }; \
  104. \
  105. template< \
  106. BOOST_MPL_PP_DEFAULT_PARAMS(arity, typename P, na) \
  107. > \
  108. struct name \
  109. { \
  110. typedef typename eval_if< \
  111. is_na<BOOST_PP_CAT(P, arity)> \
  112. , def_##name##_impl<BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P)> \
  113. , aux::name##_impl<BOOST_MPL_PP_PARAMS(arity, P)> \
  114. >::type type; \
  115. }; \
  116. \
  117. template< \
  118. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), typename P) \
  119. > \
  120. struct def_reverse_##name##_impl \
  121. : if_< has_push_back<P1> \
  122. , aux::reverse_##name##_impl< \
  123. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  124. , back_inserter< typename clear<P1>::type > \
  125. > \
  126. , aux::name##_impl< \
  127. BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P) \
  128. , front_inserter< typename clear<P1>::type > \
  129. > \
  130. >::type \
  131. { \
  132. }; \
  133. template< \
  134. BOOST_MPL_PP_DEFAULT_PARAMS(arity, typename P, na) \
  135. > \
  136. struct reverse_##name \
  137. { \
  138. typedef typename eval_if< \
  139. is_na<BOOST_PP_CAT(P, arity)> \
  140. , def_reverse_##name##_impl<BOOST_MPL_PP_PARAMS(BOOST_PP_DEC(arity), P)> \
  141. , aux::reverse_##name##_impl<BOOST_MPL_PP_PARAMS(arity, P)> \
  142. >::type type; \
  143. }; \
  144. BOOST_MPL_AUX_NA_SPEC(arity, name) \
  145. BOOST_MPL_AUX_NA_SPEC(arity, reverse_##name) \
  146. /**/
  147. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  148. #endif // BOOST_MPL_AUX_INSERTER_ALGORITHM_HPP_INCLUDED