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