@@ -111,6 +111,80 @@ struct CopyFromForwardIterToBitIter {
111111 }
112112};
113113
114+ // Test std::copy with segmented iterators: deque<T>::iterator, join_view::iterator
115+ TEST_CONSTEXPR_CXX23 void test_segmented_iterator () {
116+ // std::deque iterator
117+ { // Copy from segmented input to contiguous output (deque<int> to vector<int>)
118+ std::deque<int > in (20 );
119+ for (std::size_t i = 0 ; i < in.size (); ++i)
120+ in[i] = i;
121+ std::vector<int > out (in.size ());
122+ std::copy (in.begin (), in.end (), out.begin ());
123+ assert (std::equal (in.begin (), in.end (), out.begin ()));
124+ }
125+ { // Copy from contiguous input to segmented output (vector<int> to deque<int>)
126+ std::vector<int > in (20 );
127+ for (std::size_t i = 0 ; i < in.size (); ++i)
128+ in[i] = i;
129+ std::deque<int > out (in.size ());
130+ std::copy (in.begin (), in.end (), out.begin ());
131+ assert (std::equal (in.begin (), in.end (), out.begin ()));
132+ }
133+ { // Copy from segmented input to segmented output (deque<int> to deque<int>)
134+ std::deque<int > in (20 );
135+ for (std::size_t i = 0 ; i < in.size (); ++i)
136+ in[i] = i;
137+ std::deque<int > out (in.size ());
138+ std::copy (in.begin (), in.end (), out.begin ());
139+ assert (in == out);
140+ }
141+ { // Copy from segmented input to vector<bool> output
142+ std::deque<bool > in (199 , false );
143+ for (std::size_t i = 0 ; i < in.size (); i += 2 )
144+ in[i] = true ;
145+ std::vector<bool > out (in.size ());
146+ std::copy (in.begin (), in.end (), out.begin ());
147+ assert (std::equal (in.begin (), in.end (), out.begin ()));
148+ }
149+ { // Copy from vector<bool> input to segmented output
150+ std::vector<bool > in (199 , false );
151+ for (std::size_t i = 0 ; i < in.size (); i += 2 )
152+ in[i] = true ;
153+ std::deque<bool > out (in.size ());
154+ std::copy (in.begin (), in.end (), out.begin ());
155+ assert (std::equal (in.begin (), in.end (), out.begin ()));
156+ }
157+
158+ #if TEST_STD_VER >= 20
159+ // join_view iterator
160+ { // Copy from segmented input to contiguous output (join_viw to vector<int>)
161+ std::vector<std::vector<int >> v{{1 , 2 }, {1 , 2 , 3 }, {0 , 0 }, {3 , 4 , 5 }, {6 }, {7 , 8 , 9 , 6 }, {0 , 1 , 2 , 3 , 0 , 1 , 2 }};
162+ auto jv = std::ranges::join_view (v);
163+ std::vector<int > expected (jv.begin (), jv.end ());
164+ std::vector<int > out (expected.size ());
165+ std::copy (jv.begin (), jv.end (), out.begin ());
166+ assert (out == expected);
167+ }
168+ // Copy from segmented input to segmented output (join_view to deque)
169+ if (!TEST_IS_CONSTANT_EVALUATED) { // TODO: enable this for constant evaluation when std::deque is fully constexpr
170+ std::vector<std::vector<int >> v{{1 , 2 }, {1 , 2 , 3 }, {0 , 0 }, {3 , 4 , 5 }, {6 }, {7 , 8 , 9 , 6 }, {0 , 1 , 2 , 3 , 0 , 1 , 2 }};
171+ auto jv = std::ranges::join_view (v);
172+ std::deque<int > expected (jv.begin (), jv.end ());
173+ std::deque<int > out (expected.size ());
174+ std::copy (jv.begin (), jv.end (), out.begin ());
175+ assert (out == expected);
176+ }
177+ { // Copy from segmented input to vector<bool> output
178+ std::vector<std::vector<int >> v{{1 , 1 }, {1 , 0 , 1 }, {0 , 0 }, {1 , 1 , 1 }, {1 }, {1 , 1 , 1 , 1 }, {0 , 0 , 1 , 1 , 0 , 1 , 1 }};
179+ auto jv = std::ranges::join_view (v);
180+ std::vector<bool > expected (jv.begin (), jv.end ());
181+ std::vector<bool > out (expected.size ());
182+ std::copy (jv.begin (), jv.end (), out.begin ());
183+ assert (out == expected);
184+ }
185+ #endif
186+ }
187+
114188TEST_CONSTEXPR_CXX20 bool test () {
115189 types::for_each (types::cpp17_input_iterator_list<const int *>(), TestInIters ());
116190
@@ -294,81 +368,8 @@ TEST_CONSTEXPR_CXX20 bool test() {
294368 types::for_each (types::forward_iterator_list<bool *>(), CopyFromForwardIterToBitIter<299 >());
295369 }
296370
297- // Test std::copy with segmented iterators: deque<T>::iterator, join_view::iterator
298- {
299- // std::deque iterator
300- if (!TEST_IS_CONSTANT_EVALUATED) { // TODO: enable this for constant evaluation when std::deque is fully constexpr
301- { // Copy from segmented input to contiguous output (deque<int> to vector<int>)
302- std::deque<int > in (20 );
303- for (std::size_t i = 0 ; i < in.size (); ++i)
304- in[i] = i;
305- std::vector<int > out (in.size ());
306- std::copy (in.begin (), in.end (), out.begin ());
307- assert (std::equal (in.begin (), in.end (), out.begin ()));
308- }
309- { // Copy from contiguous input to segmented output (vector<int> to deque<int>)
310- std::vector<int > in (20 );
311- for (std::size_t i = 0 ; i < in.size (); ++i)
312- in[i] = i;
313- std::deque<int > out (in.size ());
314- std::copy (in.begin (), in.end (), out.begin ());
315- assert (std::equal (in.begin (), in.end (), out.begin ()));
316- }
317- { // Copy from segmented input to segmented output (deque<int> to deque<int>)
318- std::deque<int > in (20 );
319- for (std::size_t i = 0 ; i < in.size (); ++i)
320- in[i] = i;
321- std::deque<int > out (in.size ());
322- std::copy (in.begin (), in.end (), out.begin ());
323- assert (in == out);
324- }
325- { // Copy from segmented input to vector<bool> output
326- std::deque<bool > in (199 , false );
327- for (std::size_t i = 0 ; i < in.size (); i += 2 )
328- in[i] = true ;
329- std::vector<bool > out (in.size ());
330- std::copy (in.begin (), in.end (), out.begin ());
331- assert (std::equal (in.begin (), in.end (), out.begin ()));
332- }
333- { // Copy from vector<bool> input to segmented output
334- std::vector<bool > in (199 , false );
335- for (std::size_t i = 0 ; i < in.size (); i += 2 )
336- in[i] = true ;
337- std::deque<bool > out (in.size ());
338- std::copy (in.begin (), in.end (), out.begin ());
339- assert (std::equal (in.begin (), in.end (), out.begin ()));
340- }
341- }
342-
343- #if TEST_STD_VER >= 20
344- // join_view iterator
345- { // Copy from segmented input to contiguous output (join_viw to vector<int>)
346- std::vector<std::vector<int >> v{{1 , 2 }, {1 , 2 , 3 }, {0 , 0 }, {3 , 4 , 5 }, {6 }, {7 , 8 , 9 , 6 }, {0 , 1 , 2 , 3 , 0 , 1 , 2 }};
347- auto jv = std::ranges::join_view (v);
348- std::vector<int > expected (jv.begin (), jv.end ());
349- std::vector<int > out (expected.size ());
350- std::copy (jv.begin (), jv.end (), out.begin ());
351- assert (out == expected);
352- }
353- // Copy from segmented input to segmented output (join_view to deque)
354- if (!TEST_IS_CONSTANT_EVALUATED) { // TODO: enable this for constant evaluation when std::deque is fully constexpr
355- std::vector<std::vector<int >> v{{1 , 2 }, {1 , 2 , 3 }, {0 , 0 }, {3 , 4 , 5 }, {6 }, {7 , 8 , 9 , 6 }, {0 , 1 , 2 , 3 , 0 , 1 , 2 }};
356- auto jv = std::ranges::join_view (v);
357- std::deque<int > expected (jv.begin (), jv.end ());
358- std::deque<int > out (expected.size ());
359- std::copy (jv.begin (), jv.end (), out.begin ());
360- assert (out == expected);
361- }
362- { // Copy from segmented input to vector<bool> output
363- std::vector<std::vector<int >> v{{1 , 1 }, {1 , 0 , 1 }, {0 , 0 }, {1 , 1 , 1 }, {1 }, {1 , 1 , 1 , 1 }, {0 , 0 , 1 , 1 , 0 , 1 , 1 }};
364- auto jv = std::ranges::join_view (v);
365- std::vector<bool > expected (jv.begin (), jv.end ());
366- std::vector<bool > out (expected.size ());
367- std::copy (jv.begin (), jv.end (), out.begin ());
368- assert (out == expected);
369- }
370- #endif
371- }
371+ if (!TEST_IS_CONSTANT_EVALUATED) // TODO: enable this unconditionally when std::deque is fully constexpr
372+ test_segmented_iterator ();
372373
373374 return true ;
374375}
0 commit comments