copy.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. // Copyright David Abrahams 2003-2004
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/mpl for documentation.
  9. // $Id$
  10. // $Date$
  11. // $Revision$
  12. #include <boost/mpl/copy.hpp>
  13. #include <boost/mpl/vector/vector20_c.hpp>
  14. #include <boost/mpl/vector/vector0.hpp>
  15. #include <boost/mpl/range_c.hpp>
  16. #include <boost/mpl/front_inserter.hpp>
  17. #include <boost/mpl/size.hpp>
  18. #include <boost/mpl/equal.hpp>
  19. #include <boost/mpl/less.hpp>
  20. #include <boost/mpl/begin_end_fwd.hpp>
  21. #include <boost/mpl/size_fwd.hpp>
  22. #include <boost/mpl/empty_fwd.hpp>
  23. #include <boost/mpl/front_fwd.hpp>
  24. #include <boost/mpl/insert_fwd.hpp>
  25. #include <boost/mpl/insert_range_fwd.hpp>
  26. #include <boost/mpl/erase_fwd.hpp>
  27. #include <boost/mpl/clear_fwd.hpp>
  28. #include <boost/mpl/push_back_fwd.hpp>
  29. #include <boost/mpl/pop_back_fwd.hpp>
  30. #include <boost/mpl/back_fwd.hpp>
  31. #include <boost/mpl/aux_/test.hpp>
  32. MPL_TEST_CASE()
  33. {
  34. typedef vector10_c<int,9,8,7,6,5,4,3,2,1,0> answer;
  35. typedef copy<
  36. range_c<int,0,10>
  37. , mpl::front_inserter< vector0<> >
  38. >::type result;
  39. MPL_ASSERT_RELATION( size<result>::value, ==, 10 );
  40. MPL_ASSERT(( equal< result,answer > ));
  41. }
  42. MPL_TEST_CASE()
  43. {
  44. typedef vector10_c<int,10,11,12,13,14,15,16,17,18,19> numbers;
  45. typedef reverse_copy<
  46. range_c<int,0,10>
  47. , mpl::front_inserter<numbers>
  48. >::type result;
  49. MPL_ASSERT_RELATION( size<result>::value, ==, 20 );
  50. MPL_ASSERT(( equal< result,range_c<int,0,20> > ));
  51. }
  52. struct push_back_only_tag {};
  53. template< typename Seq >
  54. struct push_back_only
  55. {
  56. typedef push_back_only_tag tag;
  57. typedef Seq seq;
  58. };
  59. namespace boost { namespace mpl {
  60. template<>
  61. struct begin_impl< ::push_back_only_tag >
  62. {
  63. template< typename Seq > struct apply
  64. : begin< typename Seq::seq >
  65. {
  66. };
  67. };
  68. template<>
  69. struct end_impl< ::push_back_only_tag >
  70. {
  71. template< typename Seq > struct apply
  72. : end< typename Seq::seq >
  73. {
  74. };
  75. };
  76. template<>
  77. struct size_impl< ::push_back_only_tag >
  78. {
  79. template< typename Seq > struct apply
  80. : size< typename Seq::seq >
  81. {
  82. };
  83. };
  84. template<>
  85. struct empty_impl< ::push_back_only_tag >
  86. {
  87. template< typename Seq > struct apply
  88. : empty< typename Seq::seq >
  89. {
  90. };
  91. };
  92. template<>
  93. struct front_impl< ::push_back_only_tag >
  94. {
  95. template< typename Seq > struct apply
  96. : front< typename Seq::seq >
  97. {
  98. };
  99. };
  100. template<>
  101. struct insert_impl< ::push_back_only_tag >
  102. {
  103. template< typename Seq, typename Pos, typename X > struct apply
  104. {
  105. typedef ::push_back_only<
  106. typename insert< typename Seq::seq, Pos, X >::type
  107. > type;
  108. };
  109. };
  110. template<>
  111. struct insert_range_impl< ::push_back_only_tag >
  112. {
  113. template< typename Seq, typename Pos, typename X > struct apply
  114. {
  115. typedef ::push_back_only<
  116. typename insert_range< typename Seq::seq, Pos, X >::type
  117. > type;
  118. };
  119. };
  120. template<>
  121. struct erase_impl< ::push_back_only_tag >
  122. {
  123. template< typename Seq, typename Iter1, typename Iter2 > struct apply
  124. {
  125. typedef ::push_back_only<
  126. typename erase< typename Seq::seq, Iter1, Iter2 >::type
  127. > type;
  128. };
  129. };
  130. template<>
  131. struct clear_impl< ::push_back_only_tag >
  132. {
  133. template< typename Seq > struct apply
  134. {
  135. typedef ::push_back_only<
  136. typename clear< typename Seq::seq >::type
  137. > type;
  138. };
  139. };
  140. template<>
  141. struct push_back_impl< ::push_back_only_tag >
  142. {
  143. template< typename Seq, typename X > struct apply
  144. {
  145. typedef ::push_back_only<
  146. typename push_back< typename Seq::seq, X >::type
  147. > type;
  148. };
  149. };
  150. template<>
  151. struct pop_back_impl< ::push_back_only_tag >
  152. {
  153. template< typename Seq > struct apply
  154. {
  155. typedef ::push_back_only<
  156. typename pop_back< typename Seq::seq >::type
  157. > type;
  158. };
  159. };
  160. template<>
  161. struct back_impl< ::push_back_only_tag >
  162. {
  163. template< typename Seq > struct apply
  164. : back< typename Seq::seq >
  165. {
  166. };
  167. };
  168. template<>
  169. struct has_push_back_impl< ::push_back_only_tag >
  170. {
  171. template< typename Seq > struct apply
  172. : less< size<Seq>,int_<10> >
  173. {
  174. };
  175. };
  176. }}
  177. MPL_TEST_CASE()
  178. {
  179. typedef vector10_c<int,0,1,2,3,4,5,6,7,8,9> numbers;
  180. typedef copy< push_back_only< numbers > >::type result;
  181. MPL_ASSERT((equal< numbers, result >));
  182. }