63 printf(
"list: %d { ", (
int)data.size());
72 printf(
"%s: %d { ", pre.c_str(), (
int)data.size());
80static void fill_list(T& data,
const std::size_t size) {
84 data.emplace_back(
static_cast<uint64_t
>(i+1) );
86 REQUIRE(i == data.size());
94 typename std::enable_if<
95 std::is_class<Iter>::value
108 typename std::enable_if<
109 !std::is_class<Iter>::value
117 typedef typename T::size_type size_type;
118 typedef typename T::iterator iter_type;
119 typedef typename T::difference_type diff_type;
120 typedef typename T::const_iterator citer_type;
122 printf(
"**** Type Info: %s\n", type_id.c_str());
129 print_iterator_info<iter_type>(
"T::iterator");
130 print_iterator_info<citer_type>(
"T::citer_type");
139template<
class T,
typename iterator_type1,
typename iterator_type2>
145 REQUIRE( citer1 == citer2 );
146 REQUIRE( citer2 == citer1 );
147 REQUIRE( !( citer1 != citer2 ) );
148 REQUIRE( !( citer2 != citer1 ) );
149 REQUIRE( *citer1 == *citer2 );
150 REQUIRE( *citer2 == *citer1 );
151 REQUIRE( !( *citer1 != *citer2 ) );
152 REQUIRE( !( *citer2 != *citer1 ) );
154template<
class T,
typename iterator_type1,
typename iterator_type2>
160 REQUIRE( citer1 != citer2 );
161 REQUIRE( citer2 != citer1 );
162 REQUIRE( !( citer1 == citer2 ) );
163 REQUIRE( !( citer2 == citer1 ) );
164 REQUIRE( *citer1 != *citer2 );
165 REQUIRE( *citer2 != *citer1 );
166 REQUIRE( !( *citer1 == *citer2 ) );
167 REQUIRE( !( *citer2 == *citer1 ) );
171template<
class T,
typename iterator_type1,
typename iterator_type2,
typename iterator_type3,
typename iterator_type4>
173 iterator_type1& begin,
175 iterator_type3& citer1, iterator_type4& citer2,
176 const typename T::difference_type citer1_idx,
177 const typename T::difference_type citer2_idx)
179 typedef typename T::difference_type diff_type;
181 diff_type d_size =
static_cast<diff_type
>(size);
182 diff_type distance = citer2_idx - citer1_idx;
185 REQUIRE( ( end - begin ) == d_size);
186 REQUIRE( ( citer2 - begin ) == citer2_idx);
187 REQUIRE( ( citer1 - begin ) == citer1_idx);
188 REQUIRE( ( end - citer1 ) == d_size - citer1_idx);
189 REQUIRE( ( end - citer2 ) == d_size - citer2_idx);
190 REQUIRE( ( citer2 - citer1 ) == distance);
193 REQUIRE( ( citer1 - citer1_idx ) == begin);
194 REQUIRE( ( citer2 - citer2_idx ) == begin);
195 REQUIRE( ( citer2 - distance ) == citer1);
199 diff_type d_citer1_end = end - citer1;
200 diff_type d_citer2_end = end - citer2;
201 REQUIRE( ( citer1_idx + d_citer1_end ) == d_size);
202 REQUIRE( ( citer2_idx + d_citer2_end ) == d_size);
204 REQUIRE( ( citer1 + d_citer1_end ) == end);
205 REQUIRE( ( citer2 + d_citer2_end ) == end);
211 if( 0 == distance ) {
212 test_iterator_equal<T>(citer1, citer2);
213 REQUIRE( !( citer2 > citer1 ) );
214 REQUIRE( citer2 >= citer1 );
215 REQUIRE( !( citer2 < citer1 ) );
216 REQUIRE( citer2 <= citer1 );
217 REQUIRE( citer1 <= citer2 );
218 REQUIRE( citer1 >= citer2 );
219 }
else if( distance > 0 ) {
220 test_iterator_notequal<T>(citer1, citer2);
221 REQUIRE( citer2 > citer1 );
222 REQUIRE( citer2 >= citer1 );
223 REQUIRE( !( citer2 < citer1 ) );
224 REQUIRE( !( citer2 <= citer1 ) );
225 REQUIRE( citer1 <= citer2 );
226 REQUIRE( citer1 < citer2 );
228 test_iterator_notequal<T>(citer1, citer2);
229 REQUIRE( !( citer2 > citer1 ) );
230 REQUIRE( !( citer2 >= citer1 ) );
231 REQUIRE( citer2 < citer1 );
232 REQUIRE( citer2 <= citer1 );
233 REQUIRE( citer1 > citer2 );
234 REQUIRE( citer1 >= citer2 );
238template<
class T,
typename iterator_type1,
typename iterator_type2>
240 iterator_type1& begin, iterator_type2& end)
242 printf(
"**** test_iterator_dereference:\n");
243 print_iterator_info<iterator_type1>(
"iterator_type1");
244 print_iterator_info<iterator_type2>(
"iterator_type2");
247 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
248 T data_has( begin, end );
249 REQUIRE(data_has == data_exp);
253 iterator_type1 citer1 = begin;
254 iterator_type2 citer2 = begin;
256 REQUIRE( citer1 == begin );
257 REQUIRE( citer2 == begin );
258 REQUIRE( citer1 == citer1 );
259 REQUIRE( citer2 == citer1 );
261 REQUIRE( *citer1 == *begin );
262 REQUIRE( *citer2 == *begin );
263 REQUIRE( *citer1 == *citer1 );
264 REQUIRE( *citer2 == *citer1 );
266 REQUIRE( citer1[1] == *(begin+1) );
267 REQUIRE( citer2[1] == *(begin+1) );
268 REQUIRE( citer1[1] == *(citer2+1) );
270 REQUIRE( citer1 != end-1 );
271 REQUIRE( citer2 != end-1 );
272 REQUIRE( *citer1 != *(end-1) );
273 REQUIRE( *citer2 != *(end-1) );
274 REQUIRE( citer1[1] != *(end-2) );
275 REQUIRE( citer2[1] != *(end-2) );
277 REQUIRE( citer2+size-1 == end -1 );
278 REQUIRE( *(citer2+size-1) == *(end -1) );
279 REQUIRE( citer2[size-1] == end[-1] );
281 REQUIRE( *(citer2+0) == begin[0] );
282 REQUIRE( *(citer2+1) == begin[1] );
283 REQUIRE( *(citer2+2) == begin[2] );
284 REQUIRE( *(citer2+3) == begin[3] );
285 REQUIRE( *(citer2+size-1) == end[-1] );
287 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
290template<
class T,
typename iterator_type1,
typename iterator_type2>
292 iterator_type1& begin, iterator_type2& end)
294 printf(
"**** test_iterator_arithmetic:\n");
295 print_iterator_info<iterator_type1>(
"iterator_type1");
296 print_iterator_info<iterator_type2>(
"iterator_type2");
302 iterator_type1 citer1 = begin;
303 iterator_type1 citer2 = begin;
304 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
308 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 1);
312 test_iterator_compare<T>(size, begin, end, citer1, citer2, 1, 1);
316 test_iterator_compare<T>(size, begin, end, citer1, citer2, 1, 0);
320 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
321 REQUIRE( *citer2 == begin[0] );
325 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 1);
326 REQUIRE( *citer2 == *(begin+1) );
327 REQUIRE( *citer2 == begin[1] );
331 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 2);
332 REQUIRE( *citer2 == *(begin+2) );
333 REQUIRE( *citer2 == begin[2] );
337 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 3);
338 REQUIRE( *citer2 == *(begin+3) );
339 REQUIRE( *citer2 == begin[3] );
345 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
346 REQUIRE( *citer2 == *(begin+0) );
347 REQUIRE( *citer2 == begin[0] );
351 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 3);
355 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 9);
359 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
365 iterator_type1 citer1 = begin;
366 iterator_type1 citer2 = begin;
368 REQUIRE( citer1 == citer1 );
369 REQUIRE( citer2 == citer1 );
372 REQUIRE( citer2 != citer1 );
373 REQUIRE( citer1 != citer2 );
374 REQUIRE( citer2 > citer1 );
375 REQUIRE( citer2 >= citer1 );
376 REQUIRE( citer1 < citer2 );
377 REQUIRE( citer1 <= citer2 );
378 REQUIRE( ( citer2 - citer1 ) == 1);
379 REQUIRE( ( citer1 - citer2 ) == -1);
388 typedef typename T::const_iterator citer_type;
389 typedef typename T::difference_type diff_type;
394 printf(
"**** test_citer_type_ops(CoW): %s\n", type_id.c_str());
396 citer_type begin = data.cbegin();
397 citer_type end = begin.cend();
398 diff_type data_size =
static_cast<diff_type
>(data.size());
399 diff_type begin_size =
static_cast<diff_type
>(begin.size());
400 diff_type end_size =
static_cast<diff_type
>(end.size());
401 REQUIRE( begin_size == data_size );
402 REQUIRE( end_size == data_size );
403 REQUIRE( end - begin == data_size );
404 REQUIRE( end - end_size == begin );
405 REQUIRE( begin + begin_size == end );
406 REQUIRE( *( end - end_size ) == *begin );
407 REQUIRE( *( begin + begin_size -1 ) == *(end-1) );
408 test_iterator_dereference<T, citer_type>(begin.size(), begin, end);
412 citer_type begin = data.cbegin();
413 citer_type end = begin.cend();
414 test_iterator_arithmetic<T, citer_type>(data.size(), begin, end);
417 T data2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
420 REQUIRE(data == data2);
428 typedef typename T::const_iterator citer_type;
429 typedef typename T::difference_type diff_type;
433 printf(
"**** test_citer_type_ops: %s\n", type_id.c_str());
435 citer_type begin = data.cbegin();
436 citer_type end = data.cend();
437 diff_type data_size =
static_cast<diff_type
>(data.size());
438 REQUIRE( end - begin == data_size );
439 REQUIRE( end - data_size == begin );
440 REQUIRE( begin + data_size == end );
441 REQUIRE( *( end - data_size ) == *begin );
442 REQUIRE( *( begin + data_size - 1 ) == *( end - 1 ) );
443 REQUIRE( end[-data_size] == begin[0] );
444 REQUIRE( begin[data_size - 1] == end[-1] );
445 test_iterator_dereference<T, citer_type>(data.size(), begin, end);
449 citer_type begin = data.cbegin();
450 citer_type end = data.cend();
451 test_iterator_arithmetic<T, citer_type, citer_type>(data.size(), begin, end);
454 T data2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
455 REQUIRE(data == data2);
464 typedef typename T::size_type size_type;
465 typedef typename T::const_iterator citer_type;
466 typedef typename T::iterator iter_type;
467 typedef typename T::difference_type diff_type;
468 typedef typename T::value_type value_type;
469 typedef typename T::storage_t storage_t;
471 printf(
"**** test_mutable_iterator_ops(CoW): %s\n", type_id.c_str());
475 iter_type begin = data.begin();
476 iter_type end = begin.end();
477 diff_type data_size =
static_cast<diff_type
>(data.size());
478 diff_type begin_size =
static_cast<diff_type
>(begin.size());
479 diff_type end_size =
static_cast<diff_type
>(end.size());
480 REQUIRE( begin_size == data_size );
481 REQUIRE( end_size == data_size );
482 REQUIRE( end - begin == data_size );
483 REQUIRE( end - end_size == begin );
484 REQUIRE( begin + begin_size == end );
485 REQUIRE( *( end - end_size ) == *begin );
486 REQUIRE( *( begin + begin_size - 1 ) == *( end - 1 ) );
487 REQUIRE( end[-end_size] == begin[0] );
488 REQUIRE( begin[begin_size - 1] == end[-1] );
489 test_iterator_dereference<T, iter_type>(begin.size(), begin, end);
497 iter_type begin = data.begin();
498 iter_type end = begin.end();
499 citer_type cbegin = begin.immutable();
500 citer_type cend = cbegin.cend();
502 test_iterator_arithmetic<T>(data.size(), begin, end);
503 test_iterator_arithmetic<T>(data.size(), cbegin, cend);
504 test_iterator_arithmetic<T>(data.size(), begin, cend);
505 test_iterator_arithmetic<T>(data.size(), cbegin, end);
525 citer_type citer0 = data.cbegin();
527 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
528 REQUIRE(data == data_exp);
530 REQUIRE( *data.snapshot() == citer0.storage() );
532 iter_type iter = data.begin();
533 size_type size_pre = iter.size();
534 value_type elem = iter.end()[-2];
536 REQUIRE( iter != citer0 );
537 REQUIRE( iter.storage() == citer0.storage() );
538 REQUIRE( iter.storage() == *data.snapshot() );
540 REQUIRE( iter.dist_begin() == 0 );
541 REQUIRE( iter.dist_end() ==
static_cast<diff_type
>(size_pre));
547 REQUIRE( iter.size() == size_pre-1 );
548 REQUIRE( iter == iter.end() );
549 REQUIRE( iter == iter.begin()+size_pre-1 );
550 REQUIRE( iter.dist_begin() ==
static_cast<diff_type
>(size_pre)-1 );
551 REQUIRE( iter.dist_end() == 0 );
552 REQUIRE( iter[-1] == elem );
554 storage_t data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
555 REQUIRE(iter.storage() == data_exp);
557 REQUIRE(iter.storage() != citer0.storage());
558 REQUIRE(iter.storage() != *data.snapshot());
561 REQUIRE( iter == iter.end() );
562 size_pre = iter.size();
563 REQUIRE( iter.dist_begin() ==
static_cast<diff_type
>(size_pre));
564 REQUIRE( iter.dist_end() == 0);
569 iter.insert(data2.cbegin(), data2.cbegin()+data2.size());
571 REQUIRE( iter.size() == size_pre+10 );
572 REQUIRE( iter == iter.end()-10 );
573 REQUIRE( iter.dist_begin() ==
static_cast<diff_type
>(size_pre));
574 REQUIRE( iter.dist_end() == 10);
576 storage_t data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
577 REQUIRE(iter.storage() == data_exp);
581 REQUIRE( iter == iter.end()-10 );
582 size_pre = iter.size();
586 REQUIRE( iter.size() == size_pre-10 );
587 REQUIRE( iter == iter.end() );
589 storage_t data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
590 REQUIRE(iter.storage() == data_exp);
594 size_pre = iter.size();
596 REQUIRE( iter == iter.begin() );
597 elem = iter.begin()[1];
599 REQUIRE( iter.size() == size_pre-1 );
600 REQUIRE( iter == iter.begin() );
601 REQUIRE( *iter == elem );
603 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
604 REQUIRE(iter.storage() == data_exp);
608 size_pre = iter.size();
609 REQUIRE( iter == iter.begin() );
610 elem = iter.end()[-1];
614 citer_type data2_iter = data2.cbegin();
615 iter.push_back(data2_iter[0]);
616 iter.push_back(data2_iter[1]);
617 iter.push_back(data2_iter[2]);
618 REQUIRE( iter.size() == size_pre+3 );
619 REQUIRE( iter == iter.end() );
620 REQUIRE( iter[-3] == data2_iter[0] );
621 REQUIRE( iter[-2] == data2_iter[1] );
622 REQUIRE( iter[-1] == data2_iter[2] );
625 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3 };
626 REQUIRE(iter.storage() == data_exp);
630 size_pre = iter.size();
631 REQUIRE( iter == iter.end() );
634 REQUIRE( iter.size() == size_pre-3 );
635 REQUIRE( iter == iter.end() );
637 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
638 REQUIRE(iter.storage() == data_exp);
642 size_pre = iter.size();
643 REQUIRE( iter == iter.end() );
645 value_type elem0 = iter.begin()[0];
646 iter.push_back( std::move(elem0));
649 value_type elem0 = iter.begin()[1];
650 iter.push_back( std::move(elem0));
653 value_type elem0 = iter.begin()[2];
654 iter.push_back( std::move(elem0));
656 REQUIRE( iter.size() == size_pre+3 );
657 REQUIRE( iter == iter.end() );
658 REQUIRE( iter[-3] == iter.begin()[0] );
659 REQUIRE( iter[-2] == iter.begin()[1] );
660 REQUIRE( iter[-1] == iter.begin()[2] );
662 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4 };
663 REQUIRE(iter.storage() == data_exp);
667 REQUIRE( iter == iter.end() );
672 REQUIRE( iter == iter.end() );
674 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
675 REQUIRE(iter.storage() == data_exp);
681 REQUIRE( iter == iter.begin()+5 );
682 REQUIRE( iter.dist_begin() == 5 );
684 size_pre = iter.size();
688 citer_type data2_iter = data2.cbegin();
689 iter.insert(data2_iter[0]);
690 iter.insert(data2_iter[1]);
691 iter.insert(data2_iter[2]);
692 REQUIRE( iter.size() == size_pre+3 );
693 REQUIRE( iter == iter.begin()+5 );
695 REQUIRE( iter[5] == data2_iter[2] );
696 REQUIRE( iter[6] == data2_iter[1] );
697 REQUIRE( iter[7] == data2_iter[0] );
700 storage_t data_exp = { 2, 3, 4, 5, 6, 3, 2, 1, 7, 8, 9 };
701 REQUIRE(iter.storage() == data_exp);
706 REQUIRE( iter == iter.begin()+5 );
707 size_pre = iter.size();
711 iter.insert(data2.cbegin(), data2.cbegin()+3);
713 REQUIRE( iter.size() == size_pre+3 );
714 REQUIRE( iter == iter.begin()+5 );
716 storage_t data_exp = { 2, 3, 4, 5, 6, 1, 2, 3, 3, 2, 1, 7, 8, 9 };
717 REQUIRE(iter.storage() == data_exp);
721 REQUIRE( iter == iter.begin()+5 );
722 size_pre = iter.size();
724 REQUIRE( iter.size() == size_pre-6 );
725 REQUIRE( iter == iter.begin()+5 );
727 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
728 REQUIRE(iter.storage() == data_exp);
732 size_pre = iter.size();
733 REQUIRE( iter == iter.begin()+5 );
734 iter.emplace(
static_cast<uint64_t
>(2) );
735 iter.emplace(
static_cast<uint64_t
>(3) );
736 iter.emplace(
static_cast<uint64_t
>(4) );
737 REQUIRE( iter == iter.begin()+5 );
738 REQUIRE( iter[0] == 4 );
739 REQUIRE( iter[1] == 3 );
740 REQUIRE( iter[2] == 2 );
742 storage_t data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9 };
743 REQUIRE(iter.storage() == data_exp);
747 size_pre = iter.size();
748 REQUIRE( iter == iter.begin()+5 );
749 iter.emplace_back(
static_cast<uint64_t
>(2) );
750 iter.emplace_back(
static_cast<uint64_t
>(3) );
751 iter.emplace_back(
static_cast<uint64_t
>(4) );
752 REQUIRE( iter == iter.end() );
753 REQUIRE( iter[-1] == 4 );
754 REQUIRE( iter[-2] == 3 );
755 REQUIRE( iter[-3] == 2 );
757 storage_t data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9, 2, 3, 4 };
758 REQUIRE(iter.storage() == data_exp);
762 size_pre = iter.size();
763 REQUIRE( iter == iter.end() );
765 REQUIRE( iter == iter.end()-10 );
767 while( iter != iter.end() ) {
770 REQUIRE( iter.size() == size_pre - 10 );
773 storage_t data_exp = { 2, 3, 4, 5 };
774 REQUIRE(iter.storage() == data_exp);
779 REQUIRE( iter != data.cbegin() );
780 REQUIRE( iter.storage() != *data.snapshot() );
782 T data_exp = { 2, 3, 4, 5 };
783 REQUIRE(data != data_exp);
787 T data_exp = { 2, 3, 4, 5 };
788 REQUIRE(data == data_exp);
799 typedef typename T::iterator iter_type;
800 typedef typename T::const_iterator citer_type;
801 typedef typename T::difference_type diff_type;
803 printf(
"**** test_mutable_iterator_ops(___): %s\n", type_id.c_str());
807 iter_type begin = data.begin();
808 iter_type end = data.end();
809 diff_type data_size =
static_cast<diff_type
>(data.size());
810 REQUIRE( end - begin == data_size );
811 REQUIRE( end - data_size == begin );
812 REQUIRE( begin + data_size == end );
813 REQUIRE( *( end - data_size ) == *begin );
814 REQUIRE( *( begin + data_size - 1 ) == *(end -1) );
815 test_iterator_dereference<T, iter_type>(data.size(), begin, end);
823 iter_type begin = data.begin();
824 iter_type end = data.end();
825 citer_type cend = data.cend();
826 citer_type cbegin = data.cbegin();
828 test_iterator_arithmetic<T>(data.size(), begin, end);
829 test_iterator_arithmetic<T>(data.size(), cbegin, cend);
830 test_iterator_arithmetic<T>(data.size(), begin, cend);
831 test_iterator_arithmetic<T>(data.size(), cbegin, end);
851 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
852 REQUIRE(data == data_exp);
855 iter_type iter = data.end();
856 typename T::size_type size_pre = data.size();
857 typename T::value_type elem = iter[-2];
864 REQUIRE( data.size() == size_pre-1 );
865 REQUIRE( iter == data.end() );
866 REQUIRE( iter == data.begin()+size_pre-1 );
867 REQUIRE( iter[-1] == elem );
869 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
870 REQUIRE(data == data_exp);
874 REQUIRE( iter == data.end() );
875 size_pre = data.size();
879 iter = data.insert(iter, data2.cbegin(), data2.cbegin()+data2.size());
881 REQUIRE( data.size() == size_pre+10 );
882 REQUIRE( iter == data.end()-10 );
884 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
885 REQUIRE(data == data_exp);
889 REQUIRE( iter == data.end()-10 );
890 size_pre = data.size();
892 iter = data.erase(iter, iter+10);
894 REQUIRE( data.size() == size_pre-10 );
895 REQUIRE( iter == data.end() );
897 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
898 REQUIRE(data == data_exp);
902 size_pre = data.size();
904 REQUIRE( iter == data.begin() );
906 iter = data.erase(iter);
907 REQUIRE( data.size() == size_pre-1 );
908 REQUIRE( iter == data.begin() );
909 REQUIRE( *iter == elem );
911 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
912 REQUIRE(data == data_exp);
916 size_pre = data.size();
917 REQUIRE( iter == data.begin() );
918 elem = data.end()[-1];
922 data.push_back(data2[0]);
923 data.push_back(data2[1]);
924 data.push_back(data2[2]);
926 REQUIRE( data.size() == size_pre+3 );
927 REQUIRE( iter == data.end() );
928 REQUIRE( iter[-3] == data2[0] );
929 REQUIRE( iter[-2] == data2[1] );
930 REQUIRE( iter[-1] == data2[2] );
933 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3 };
934 REQUIRE(data == data_exp);
938 size_pre = data.size();
939 REQUIRE( iter == data.end() );
941 iter = data.erase(iter, iter+3);
942 REQUIRE( data.size() == size_pre-3 );
943 REQUIRE( iter == data.end() );
945 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
946 REQUIRE(data == data_exp);
950 size_pre = data.size();
951 REQUIRE( iter == data.end() );
953 typename T::value_type elem0 = data.begin()[0];
954 data.push_back( std::move(elem0));
957 typename T::value_type elem0 = data.begin()[1];
958 data.push_back( std::move(elem0));
961 typename T::value_type elem0 = data.begin()[2];
962 data.push_back( std::move(elem0));
965 REQUIRE( data.size() == size_pre+3 );
966 REQUIRE( iter == data.end() );
967 REQUIRE( iter[-3] == data.begin()[0] );
968 REQUIRE( iter[-2] == data.begin()[1] );
969 REQUIRE( iter[-1] == data.begin()[2] );
971 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4 };
972 REQUIRE(data == data_exp);
976 REQUIRE( iter == data.end() );
978 iter = data.erase(iter);
979 iter = data.erase(iter);
980 iter = data.erase(iter);
981 REQUIRE( iter == data.end() );
983 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
984 REQUIRE(data == data_exp);
990 REQUIRE( iter == data.begin()+5 );
991 size_pre = data.size();
995 iter = data.insert(iter, data2[0]);
996 iter = data.insert(iter, data2[1]);
997 iter = data.insert(iter, data2[2]);
998 REQUIRE( data.size() == size_pre+3 );
999 REQUIRE( iter == data.begin()+5 );
1000 iter = data.begin();
1001 REQUIRE( iter[5] == data2[2] );
1002 REQUIRE( iter[6] == data2[1] );
1003 REQUIRE( iter[7] == data2[0] );
1006 T data_exp = { 2, 3, 4, 5, 6, 3, 2, 1, 7, 8, 9 };
1007 REQUIRE(data == data_exp);
1012 REQUIRE( iter == data.begin()+5 );
1013 size_pre = data.size();
1017 iter = data.insert(iter, data2.cbegin(), data2.cbegin()+3);
1019 REQUIRE( data.size() == size_pre+3 );
1020 REQUIRE( iter == data.begin()+5 );
1022 T data_exp = { 2, 3, 4, 5, 6, 1, 2, 3, 3, 2, 1, 7, 8, 9 };
1023 REQUIRE(data == data_exp);
1027 REQUIRE( iter == data.begin()+5 );
1028 size_pre = data.size();
1029 iter = data.erase(iter, iter+6);
1030 REQUIRE( data.size() == size_pre-6 );
1031 REQUIRE( iter == data.begin()+5 );
1033 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
1034 REQUIRE(data == data_exp);
1038 size_pre = data.size();
1039 REQUIRE( iter == data.begin()+5 );
1040 iter = data.emplace(iter,
static_cast<uint64_t
>(2) );
1041 iter = data.emplace(iter,
static_cast<uint64_t
>(3) );
1042 iter = data.emplace(iter,
static_cast<uint64_t
>(4) );
1044 REQUIRE( iter == data.begin()+5 );
1045 REQUIRE( iter[0] == 4 );
1046 REQUIRE( iter[1] == 3 );
1047 REQUIRE( iter[2] == 2 );
1049 T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9 };
1050 REQUIRE(data == data_exp);
1054 size_pre = data.size();
1055 REQUIRE( iter == data.begin()+5 );
1056 data.emplace_back(
static_cast<uint64_t
>(2) );
1057 data.emplace_back(
static_cast<uint64_t
>(3) );
1058 data.emplace_back(
static_cast<uint64_t
>(4) );
1060 REQUIRE( iter == data.end() );
1061 REQUIRE( iter[-1] == 4 );
1062 REQUIRE( iter[-2] == 3 );
1063 REQUIRE( iter[-3] == 2 );
1065 T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9, 2, 3, 4 };
1066 REQUIRE(data == data_exp);
1070 size_pre = data.size();
1071 REQUIRE( iter == data.end() );
1073 REQUIRE( iter == data.end()-10 );
1075 while( iter != data.end() ) {
1076 iter = data.erase(iter);
1078 REQUIRE( data.size() == size_pre - 10 );
1079 REQUIRE( iter == data.end() );
1082 T data_exp = { 2, 3, 4, 5 };
1083 REQUIRE(data == data_exp);
1094 REQUIRE(data == data2);
1095 REQUIRE(data == data3);
1106 test_citer_type_ops<T>(type_id);
1108 test_mutable_iterator_ops<T>(type_id);
1115 typedef typename T::size_type size_type;
1116 typedef typename T::const_iterator citer_type;
1117 typedef typename T::iterator iter_type;
1119 printf(
"**** test_cow_iterator_properties: %s\n", type_id.c_str());
1120 print_iterator_info<citer_type>(
"citer_type");
1121 print_iterator_info<iter_type>(
"iter_type");
1123 const size_type size0 = 100;
1126 REQUIRE(0 == data.get_allocator().memory_usage);
1127 REQUIRE(data.size() == 0);
1128 REQUIRE(data.capacity() == 0);
1129 REQUIRE(data.empty() ==
true);
1132 REQUIRE(0 != data.get_allocator().memory_usage);
1133 REQUIRE(data.size() == size0);
1134 REQUIRE(data.size() <= data.capacity());
1139 iter_type iter1 = data.begin();
1140 citer_type citer2 = iter1.immutable();
1141 citer_type citer3 = iter1.immutable().to_end();
1143 REQUIRE( iter1.is_begin() );
1144 REQUIRE( citer2.is_begin() );
1145 REQUIRE( citer3.is_end() );
1147 REQUIRE( iter1.dist_begin() == 0);
1148 REQUIRE( iter1.dist_end() == size0);
1149 REQUIRE( citer2.dist_begin() == 0);
1150 REQUIRE( citer2.dist_end() == size0);
1151 REQUIRE( citer3.dist_begin() == size0);
1152 REQUIRE( citer3.dist_end() == 0);
1154 REQUIRE( ( iter1 == citer2 ) ==
true);
1155 REQUIRE( ( citer2 == iter1 ) ==
true);
1158 REQUIRE( ( citer2 != iter1 ) ==
true);
1159 REQUIRE( ( iter1 != citer2 ) ==
true);
1160 REQUIRE( ( citer2 > iter1 ) ==
true);
1161 REQUIRE( ( citer2 >= iter1 ) ==
true);
1162 REQUIRE( ( iter1 < citer2 ) ==
true);
1163 REQUIRE( ( iter1 <= citer2 ) ==
true);
1164 REQUIRE( ( citer2 - iter1 ) == 1);
1165 REQUIRE( ( iter1 - citer2 ) == -1);
1166 REQUIRE( citer2.dist_begin() == 1);
1167 REQUIRE( citer2.dist_end() == size0-1);
1171 REQUIRE( ( iter1 != citer2 ) ==
true);
1172 REQUIRE( ( citer2 != iter1 ) ==
true);
1173 REQUIRE( ( iter1 > citer2 ) ==
true);
1174 REQUIRE( ( iter1 >= citer2 ) ==
true);
1175 REQUIRE( ( citer2 < iter1 ) ==
true);
1176 REQUIRE( ( citer2 <= iter1 ) ==
true);
1177 REQUIRE( ( iter1 - citer2 ) == 1);
1178 REQUIRE( ( citer2 - iter1 ) == -1);
1179 REQUIRE( iter1.dist_begin() == 1);
1180 REQUIRE( iter1.dist_end() == size0-1);
1181 REQUIRE( citer2.dist_begin() == 0);
1182 REQUIRE( citer2.dist_end() == size0);
1184 REQUIRE( ( iter1.end() == citer3 ) ==
true);
1185 REQUIRE( ( iter1.to_end() == citer3 ) ==
true);
1186 REQUIRE( iter1.is_end() );
1187 REQUIRE( citer3.is_end() );
1188 REQUIRE( iter1.dist_begin() == size0);
1189 REQUIRE( iter1.dist_end() == 0);
1193 citer_type c_begin0 = data.cbegin();
1199 printf(
"testing mutable non-const behavior.\n");
1200 citer_type c_begin1;
1202 iter_type m_begin1 = data.begin();
1203 c_begin1 = m_begin1.immutable();
1205 REQUIRE(*c_begin1 == *m_begin1);
1206 REQUIRE( c_begin1 == m_begin1);
1207 REQUIRE( ( c_begin1 - m_begin1 ) == 0);
1208 printf(
" 1st store: %s == %s, dist %u\n",
1209 to_decstring(*c_begin1,
',', 2).c_str(),
to_decstring(*m_begin1,
',', 2).c_str(), (
unsigned int)(c_begin1 - m_begin1));
1210 citer_type c_begin2;
1212 iter_type m_begin2 = data.begin();
1213 c_begin2 = m_begin2.immutable();
1215 REQUIRE(*c_begin2 == *m_begin2);
1216 REQUIRE( c_begin2 == m_begin2);
1217 REQUIRE( ( c_begin2 - m_begin2 ) == 0);
1218 printf(
" 2nd store: %s == %s, dist %u\n",
1219 to_decstring(*c_begin2,
',', 2).c_str(),
to_decstring(*m_begin2,
',', 2).c_str(), (
unsigned int)(c_begin2 - m_begin2));
1221 REQUIRE(*c_begin2 == *c_begin1);
1222 REQUIRE( c_begin2 != c_begin1);
1223 REQUIRE( ( c_begin2 - c_begin1 ) != 0);
1224 printf(
"2nd -> 1st store: %s == %s, dist %u\n",
1225 to_decstring(*c_begin2,
',', 2).c_str(),
to_decstring(*c_begin1,
',', 2).c_str(), (
unsigned int)(c_begin2 - c_begin1));
1227 m_begin2.write_back();
1230 citer_type c_begin2b = data.cbegin();
1231 REQUIRE(*c_begin2 == *c_begin2b);
1232 REQUIRE( c_begin2 == c_begin2b);
1233 REQUIRE( ( c_begin2 - c_begin2b ) == 0);
1234 printf(
"2nd -> cow == cbegin: %s == %s, dist %u\n",
1235 to_decstring(*c_begin2,
',', 2).c_str(),
to_decstring(*c_begin2b,
',', 2).c_str(), (
unsigned int)(c_begin2 - c_begin2b));
1236 printf(
"2nd -> 1st : %s == %s, dist %u\n",
1237 to_decstring(*c_begin1,
',', 2).c_str(),
to_decstring(*c_begin2,
',', 2).c_str(), (
unsigned int)(c_begin1 - c_begin2));
1239 m_begin1.write_back();
1242 citer_type c_begin1b = data.cbegin();
1243 printf(
"1st -> cow == cbegin: %s == %s, dist %u\n",
1244 to_decstring(*c_begin1,
',', 2).c_str(),
to_decstring(*c_begin1b,
',', 2).c_str(), (
unsigned int)(c_begin1 - c_begin1b));
1245 REQUIRE(*c_begin1 == *c_begin1b);
1246 REQUIRE( c_begin1 == c_begin1b);
1247 REQUIRE( ( c_begin1 - c_begin1b ) == 0);
1255TEST_CASE(
"Iterator Test 00 - Inspect all Iterator Types",
"[datatype][std][vector][darray][cow_vector][cow_darray]" ) {
1256 test_00_inspect_iterator_types< std_vector_uint64_t >(
"std::vector<T>");
1257 test_00_inspect_iterator_types< jau_darray_uint64_t >(
"jau::darray<T>");
1258 test_00_inspect_iterator_types< jau_cow_vector_uint64_t >(
"jau::cow_vector<T>");
1259 test_00_inspect_iterator_types< jau_cow_darray_uint64_t >(
"jau::cow_darray<T>");
1262TEST_CASE(
"STD Vector Test 01 - Validate Iterator and Index Operations",
"[datatype][std][vector]" ) {
1263 test_01_validate_iterator_ops< std_vector_uint64_t >(
"std::vector<T>");
1266TEST_CASE(
"JAU DArray Test 02 - Validate Iterator and Index Operations",
"[datatype][jau][darray]" ) {
1267 test_01_validate_iterator_ops< jau_darray_uint64_t >(
"jau::darray<T>");
1270TEST_CASE(
"JAU COW_Vector Test 11 - Validate Iterator Operations",
"[datatype][jau][cow_vector]" ) {
1271 test_01_validate_iterator_ops< jau_cow_vector_uint64_t >(
"jau::cow_vector<T>");
1273 test_01_cow_iterator_properties<jau_cow_vector_uint64_t>(
"jau::cow_vector<T>");
1276TEST_CASE(
"JAU COW_DArray Test 21 - Validate Iterator Operations",
"[datatype][jau][cow_darray]" ) {
1277 test_01_validate_iterator_ops< jau_cow_darray_uint64_t >(
"jau::cow_darray<T>");
1279 test_01_cow_iterator_properties<jau_cow_darray_uint64_t>(
"jau::cow_darray<T>");
Implementation of a Copy-On-Write (CoW) using jau::darray as the underlying storage,...
Implementation of a Copy-On-Write (CoW) using std::vector as the underlying storage,...
Implementation of a dynamic linear array storage, aka vector.
constexpr UnaryFunction for_each_const(T &data, UnaryFunction f, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
#define JAU_TYPENAME_CUE_ALL(A)
std::string to_decstring(const value_type &v, const char separator=',', const nsize_t width=0) noexcept
Produce a decimal string representation of an integral integer value.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
template< class T > is_cow_type<T>::value compile-time Type Trait, determining whether the given temp...
static void print(const std::string &typedefname, const TypeTraitGroup verbosity=TypeTraitGroup::NONE)
Print information of this type to stdout, potentially with all Type traits known.
jau::cow_darray< uint64_t, jau::nsize_t, counting_callocator< uint64_t > > jau_cow_darray_uint64_t
static void test_iterator_notequal(iterator_type1 &citer1, iterator_type2 &citer2)
jau::darray< uint64_t, jau::nsize_t, counting_callocator< uint64_t > > jau_darray_uint64_t
static void print_list(T &data)
static void test_iterator_arithmetic(const typename T::size_type size, iterator_type1 &begin, iterator_type2 &end)
static void print_iterator_info(const std::string &typedefname, typename std::enable_if< std::is_class< Iter >::value >::type *=nullptr)
static void test_iterator_compare(const typename T::size_type size, iterator_type1 &begin, iterator_type2 &end, iterator_type3 &citer1, iterator_type4 &citer2, const typename T::difference_type citer1_idx, const typename T::difference_type citer2_idx)
static void test_iterator_dereference(const typename T::size_type size, iterator_type1 &begin, iterator_type2 &end)
static bool test_mutable_iterator_ops(const std::string &type_id, std::enable_if_t< is_cow_type< T >::value, bool >=true)
TEST_CASE("Iterator Test 00 - Inspect all Iterator Types", "[datatype][std][vector][darray][cow_vector][cow_darray]")
static bool test_00_inspect_iterator_types(const std::string &type_id)
static bool test_01_cow_iterator_properties(const std::string &type_id)
std::vector< uint64_t, counting_allocator< uint64_t > > std_vector_uint64_t
jau::cow_vector< uint64_t, counting_allocator< uint64_t > > jau_cow_vector_uint64_t
static void test_iterator_equal(iterator_type1 &citer1, iterator_type2 &citer2)
static bool test_01_validate_iterator_ops(const std::string &type_id)
static void fill_list(T &data, const std::size_t size)
static bool test_citer_type_ops(const std::string &type_id, std::enable_if_t< is_cow_type< T >::value, bool >=true)
int printf(const char *format,...)
Operating Systems predefined macros.