transform.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef BOOST_MPL_TRANSFORM_HPP_INCLUDED
  2. #define BOOST_MPL_TRANSFORM_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-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/fold.hpp>
  15. #include <boost/mpl/reverse_fold.hpp>
  16. #include <boost/mpl/pair_view.hpp>
  17. #include <boost/mpl/is_sequence.hpp>
  18. #include <boost/mpl/eval_if.hpp>
  19. #include <boost/mpl/lambda.hpp>
  20. #include <boost/mpl/bind.hpp>
  21. #include <boost/mpl/or.hpp>
  22. #include <boost/mpl/not.hpp>
  23. #include <boost/mpl/aux_/na.hpp>
  24. #include <boost/mpl/aux_/inserter_algorithm.hpp>
  25. namespace boost { namespace mpl {
  26. namespace aux {
  27. template<
  28. typename Seq
  29. , typename Op
  30. , typename In
  31. >
  32. struct transform1_impl
  33. : fold<
  34. Seq
  35. , typename In::state
  36. , bind2< typename lambda< typename In::operation >::type
  37. , _1
  38. , bind1< typename lambda<Op>::type, _2>
  39. >
  40. >
  41. {
  42. };
  43. template<
  44. typename Seq
  45. , typename Op
  46. , typename In
  47. >
  48. struct reverse_transform1_impl
  49. : reverse_fold<
  50. Seq
  51. , typename In::state
  52. , bind2< typename lambda< typename In::operation >::type
  53. , _1
  54. , bind1< typename lambda<Op>::type, _2>
  55. >
  56. >
  57. {
  58. };
  59. template<
  60. typename Seq1
  61. , typename Seq2
  62. , typename Op
  63. , typename In
  64. >
  65. struct transform2_impl
  66. : fold<
  67. pair_view<Seq1,Seq2>
  68. , typename In::state
  69. , bind2< typename lambda< typename In::operation >::type
  70. , _1
  71. , bind2<
  72. typename lambda<Op>::type
  73. , bind1<first<>,_2>
  74. , bind1<second<>,_2>
  75. >
  76. >
  77. >
  78. {
  79. };
  80. template<
  81. typename Seq1
  82. , typename Seq2
  83. , typename Op
  84. , typename In
  85. >
  86. struct reverse_transform2_impl
  87. : reverse_fold<
  88. pair_view<Seq1,Seq2>
  89. , typename In::state
  90. , bind2< typename lambda< typename In::operation >::type
  91. , _1
  92. , bind2< typename lambda< Op >::type
  93. , bind1<first<>,_2>
  94. , bind1<second<>,_2>
  95. >
  96. >
  97. >
  98. {
  99. };
  100. } // namespace aux
  101. BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(3, transform1)
  102. BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(4, transform2)
  103. #define AUX778076_TRANSFORM_DEF(name) \
  104. template< \
  105. typename BOOST_MPL_AUX_NA_PARAM(Seq1) \
  106. , typename BOOST_MPL_AUX_NA_PARAM(Seq2OrOperation) \
  107. , typename BOOST_MPL_AUX_NA_PARAM(OperationOrInserter) \
  108. , typename BOOST_MPL_AUX_NA_PARAM(Inserter) \
  109. > \
  110. struct name \
  111. { \
  112. typedef typename eval_if< \
  113. or_< \
  114. is_na<OperationOrInserter> \
  115. , is_lambda_expression< Seq2OrOperation > \
  116. , not_< is_sequence<Seq2OrOperation> > \
  117. > \
  118. , name##1<Seq1,Seq2OrOperation,OperationOrInserter> \
  119. , name##2<Seq1,Seq2OrOperation,OperationOrInserter,Inserter> \
  120. >::type type; \
  121. }; \
  122. BOOST_MPL_AUX_NA_SPEC(4, name) \
  123. /**/
  124. AUX778076_TRANSFORM_DEF(transform)
  125. AUX778076_TRANSFORM_DEF(reverse_transform)
  126. #undef AUX778076_TRANSFORM_DEF
  127. }}
  128. #endif // BOOST_MPL_TRANSFORM_HPP_INCLUDED