30 #include <type_traits>
32 #define CATCH_CONFIG_RUNNER
34 #include <catch2/catch_amalgamated.hpp>
67 printf(
"list: %d { ", (
int)data.size());
75 static void print_list(
const std::string& pre, T& data) {
76 printf(
"%s: %d { ", pre.c_str(), (
int)data.size());
84 static void fill_list(T& data,
const std::size_t size) {
88 data.emplace_back(
static_cast<uint64_t
>(i+1) );
90 REQUIRE(i == data.size());
96 template<
class Iter >
98 typename std::enable_if<
99 std::is_class<Iter>::value
112 typename std::enable_if<
113 !std::is_class<Iter>::value
121 typedef typename T::size_type size_type;
122 typedef typename T::iterator iter_type;
123 typedef typename T::difference_type diff_type;
124 typedef typename T::const_iterator citer_type;
126 printf(
"**** Type Info: %s\n", type_id.c_str());
133 print_iterator_info<iter_type>(
"T::iterator");
134 print_iterator_info<citer_type>(
"T::citer_type");
143 template<
class T,
typename iterator_type1,
typename iterator_type2>
149 REQUIRE( citer1 == citer2 );
150 REQUIRE( citer2 == citer1 );
151 REQUIRE( !( citer1 != citer2 ) );
152 REQUIRE( !( citer2 != citer1 ) );
153 REQUIRE( *citer1 == *citer2 );
154 REQUIRE( *citer2 == *citer1 );
155 REQUIRE( !( *citer1 != *citer2 ) );
156 REQUIRE( !( *citer2 != *citer1 ) );
158 template<
class T,
typename iterator_type1,
typename iterator_type2>
164 REQUIRE( citer1 != citer2 );
165 REQUIRE( citer2 != citer1 );
166 REQUIRE( !( citer1 == citer2 ) );
167 REQUIRE( !( citer2 == citer1 ) );
168 REQUIRE( *citer1 != *citer2 );
169 REQUIRE( *citer2 != *citer1 );
170 REQUIRE( !( *citer1 == *citer2 ) );
171 REQUIRE( !( *citer2 == *citer1 ) );
175 template<
class T,
typename iterator_type1,
typename iterator_type2,
typename iterator_type3,
typename iterator_type4>
177 iterator_type1& begin,
179 iterator_type3& citer1, iterator_type4& citer2,
180 const typename T::difference_type citer1_idx,
181 const typename T::difference_type citer2_idx)
183 typedef typename T::difference_type diff_type;
185 diff_type d_size =
static_cast<diff_type
>(size);
186 diff_type distance = citer2_idx - citer1_idx;
189 REQUIRE( ( end - begin ) == d_size);
190 REQUIRE( ( citer2 - begin ) == citer2_idx);
191 REQUIRE( ( citer1 - begin ) == citer1_idx);
192 REQUIRE( ( end - citer1 ) == d_size - citer1_idx);
193 REQUIRE( ( end - citer2 ) == d_size - citer2_idx);
194 REQUIRE( ( citer2 - citer1 ) == distance);
197 REQUIRE( ( citer1 - citer1_idx ) == begin);
198 REQUIRE( ( citer2 - citer2_idx ) == begin);
199 REQUIRE( ( citer2 - distance ) == citer1);
203 diff_type d_citer1_end = end - citer1;
204 diff_type d_citer2_end = end - citer2;
205 REQUIRE( ( citer1_idx + d_citer1_end ) == d_size);
206 REQUIRE( ( citer2_idx + d_citer2_end ) == d_size);
208 REQUIRE( ( citer1 + d_citer1_end ) == end);
209 REQUIRE( ( citer2 + d_citer2_end ) == end);
215 if( 0 == distance ) {
216 test_iterator_equal<T>(citer1, citer2);
217 REQUIRE( !( citer2 > citer1 ) );
218 REQUIRE( citer2 >= citer1 );
219 REQUIRE( !( citer2 < citer1 ) );
220 REQUIRE( citer2 <= citer1 );
221 REQUIRE( citer1 <= citer2 );
222 REQUIRE( citer1 >= citer2 );
223 }
else if( distance > 0 ) {
224 test_iterator_notequal<T>(citer1, citer2);
225 REQUIRE( citer2 > citer1 );
226 REQUIRE( citer2 >= citer1 );
227 REQUIRE( !( citer2 < citer1 ) );
228 REQUIRE( !( citer2 <= citer1 ) );
229 REQUIRE( citer1 <= citer2 );
230 REQUIRE( citer1 < citer2 );
232 test_iterator_notequal<T>(citer1, citer2);
233 REQUIRE( !( citer2 > citer1 ) );
234 REQUIRE( !( citer2 >= citer1 ) );
235 REQUIRE( citer2 < citer1 );
236 REQUIRE( citer2 <= citer1 );
237 REQUIRE( citer1 > citer2 );
238 REQUIRE( citer1 >= citer2 );
242 template<
class T,
typename iterator_type1,
typename iterator_type2>
244 iterator_type1& begin, iterator_type2& end)
246 printf(
"**** test_iterator_dereference:\n");
247 print_iterator_info<iterator_type1>(
"iterator_type1");
248 print_iterator_info<iterator_type2>(
"iterator_type2");
251 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
252 T data_has( begin, end );
253 REQUIRE(data_has == data_exp);
257 iterator_type1 citer1 = begin;
258 iterator_type2 citer2 = begin;
260 REQUIRE( citer1 == begin );
261 REQUIRE( citer2 == begin );
262 REQUIRE( citer1 == citer1 );
263 REQUIRE( citer2 == citer1 );
265 REQUIRE( *citer1 == *begin );
266 REQUIRE( *citer2 == *begin );
267 REQUIRE( *citer1 == *citer1 );
268 REQUIRE( *citer2 == *citer1 );
270 REQUIRE( citer1[1] == *(begin+1) );
271 REQUIRE( citer2[1] == *(begin+1) );
272 REQUIRE( citer1[1] == *(citer2+1) );
274 REQUIRE( citer1 != end-1 );
275 REQUIRE( citer2 != end-1 );
276 REQUIRE( *citer1 != *(end-1) );
277 REQUIRE( *citer2 != *(end-1) );
278 REQUIRE( citer1[1] != *(end-2) );
279 REQUIRE( citer2[1] != *(end-2) );
281 REQUIRE( citer2+size-1 == end -1 );
282 REQUIRE( *(citer2+size-1) == *(end -1) );
283 REQUIRE( citer2[size-1] == end[-1] );
285 REQUIRE( *(citer2+0) == begin[0] );
286 REQUIRE( *(citer2+1) == begin[1] );
287 REQUIRE( *(citer2+2) == begin[2] );
288 REQUIRE( *(citer2+3) == begin[3] );
289 REQUIRE( *(citer2+size-1) == end[-1] );
291 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
294 template<
class T,
typename iterator_type1,
typename iterator_type2>
296 iterator_type1& begin, iterator_type2& end)
298 printf(
"**** test_iterator_arithmetic:\n");
299 print_iterator_info<iterator_type1>(
"iterator_type1");
300 print_iterator_info<iterator_type2>(
"iterator_type2");
306 iterator_type1 citer1 = begin;
307 iterator_type1 citer2 = begin;
308 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
312 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 1);
316 test_iterator_compare<T>(size, begin, end, citer1, citer2, 1, 1);
320 test_iterator_compare<T>(size, begin, end, citer1, citer2, 1, 0);
324 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
325 REQUIRE( *citer2 == begin[0] );
329 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 1);
330 REQUIRE( *citer2 == *(begin+1) );
331 REQUIRE( *citer2 == begin[1] );
335 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 2);
336 REQUIRE( *citer2 == *(begin+2) );
337 REQUIRE( *citer2 == begin[2] );
341 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 3);
342 REQUIRE( *citer2 == *(begin+3) );
343 REQUIRE( *citer2 == begin[3] );
349 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
350 REQUIRE( *citer2 == *(begin+0) );
351 REQUIRE( *citer2 == begin[0] );
355 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 3);
359 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 9);
363 test_iterator_compare<T>(size, begin, end, citer1, citer2, 0, 0);
369 iterator_type1 citer1 = begin;
370 iterator_type1 citer2 = begin;
372 REQUIRE( citer1 == citer1 );
373 REQUIRE( citer2 == citer1 );
376 REQUIRE( citer2 != citer1 );
377 REQUIRE( citer1 != citer2 );
378 REQUIRE( citer2 > citer1 );
379 REQUIRE( citer2 >= citer1 );
380 REQUIRE( citer1 < citer2 );
381 REQUIRE( citer1 <= citer2 );
382 REQUIRE( ( citer2 - citer1 ) == 1);
383 REQUIRE( ( citer1 - citer2 ) == -1);
392 typedef typename T::const_iterator citer_type;
393 typedef typename T::difference_type diff_type;
398 printf(
"**** test_citer_type_ops(CoW): %s\n", type_id.c_str());
400 citer_type begin = data.cbegin();
401 citer_type end = begin.cend();
402 diff_type data_size =
static_cast<diff_type
>(data.size());
403 diff_type begin_size =
static_cast<diff_type
>(begin.size());
404 diff_type end_size =
static_cast<diff_type
>(end.size());
405 REQUIRE( begin_size == data_size );
406 REQUIRE( end_size == data_size );
407 REQUIRE( end - begin == data_size );
408 REQUIRE( end - end_size == begin );
409 REQUIRE( begin + begin_size == end );
410 REQUIRE( *( end - end_size ) == *begin );
411 REQUIRE( *( begin + begin_size ) == *end );
412 test_iterator_dereference<T, citer_type>(begin.size(), begin, end);
416 citer_type begin = data.cbegin();
417 citer_type end = begin.cend();
418 test_iterator_arithmetic<T, citer_type>(data.size(), begin, end);
421 T data2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
424 REQUIRE(data == data2);
432 typedef typename T::const_iterator citer_type;
433 typedef typename T::difference_type diff_type;
437 printf(
"**** test_citer_type_ops: %s\n", type_id.c_str());
439 citer_type begin = data.cbegin();
440 citer_type end = data.cend();
441 diff_type data_size =
static_cast<diff_type
>(data.size());
442 REQUIRE( end - begin == data_size );
443 REQUIRE( end - data_size == begin );
444 REQUIRE( begin + data_size == end );
445 REQUIRE( *( end - data_size ) == *begin );
446 REQUIRE( *( begin + data_size - 1 ) == *( end - 1 ) );
447 REQUIRE( end[-data_size] == begin[0] );
448 REQUIRE( begin[data_size - 1] == end[-1] );
449 test_iterator_dereference<T, citer_type>(data.size(), begin, end);
453 citer_type begin = data.cbegin();
454 citer_type end = data.cend();
455 test_iterator_arithmetic<T, citer_type, citer_type>(data.size(), begin, end);
458 T data2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
459 REQUIRE(data == data2);
468 typedef typename T::size_type size_type;
469 typedef typename T::const_iterator citer_type;
470 typedef typename T::iterator iter_type;
471 typedef typename T::difference_type diff_type;
472 typedef typename T::value_type value_type;
473 typedef typename T::storage_t storage_t;
475 printf(
"**** test_mutable_iterator_ops(CoW): %s\n", type_id.c_str());
479 iter_type begin = data.begin();
480 iter_type end = begin.end();
481 diff_type data_size =
static_cast<diff_type
>(data.size());
482 diff_type begin_size =
static_cast<diff_type
>(begin.size());
483 diff_type end_size =
static_cast<diff_type
>(end.size());
484 REQUIRE( begin_size == data_size );
485 REQUIRE( end_size == data_size );
486 REQUIRE( end - begin == data_size );
487 REQUIRE( end - end_size == begin );
488 REQUIRE( begin + begin_size == end );
489 REQUIRE( *( end - end_size ) == *begin );
490 REQUIRE( *( begin + begin_size - 1 ) == *( end - 1 ) );
491 REQUIRE( end[-end_size] == begin[0] );
492 REQUIRE( begin[begin_size - 1] == end[-1] );
493 test_iterator_dereference<T, iter_type>(begin.size(), begin, end);
501 iter_type begin = data.begin();
502 iter_type end = begin.end();
503 citer_type cbegin = begin.immutable();
504 citer_type cend = cbegin.cend();
506 test_iterator_arithmetic<T>(data.size(), begin, end);
507 test_iterator_arithmetic<T>(data.size(), cbegin, cend);
508 test_iterator_arithmetic<T>(data.size(), begin, cend);
509 test_iterator_arithmetic<T>(data.size(), cbegin, end);
529 citer_type citer0 = data.cbegin();
531 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
532 REQUIRE(data == data_exp);
534 REQUIRE( *data.snapshot() == citer0.storage() );
536 iter_type iter = data.begin();
537 size_type size_pre = iter.size();
538 value_type elem = iter.end()[-2];
540 REQUIRE( iter != citer0 );
541 REQUIRE( iter.storage() == citer0.storage() );
542 REQUIRE( iter.storage() == *data.snapshot() );
544 REQUIRE( iter.dist_begin() == 0 );
545 REQUIRE( iter.dist_end() ==
static_cast<diff_type
>(size_pre));
551 REQUIRE( iter.size() == size_pre-1 );
552 REQUIRE( iter == iter.end() );
553 REQUIRE( iter == iter.begin()+size_pre-1 );
554 REQUIRE( iter.dist_begin() ==
static_cast<diff_type
>(size_pre)-1 );
555 REQUIRE( iter.dist_end() == 0 );
556 REQUIRE( iter[-1] == elem );
558 storage_t data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
559 REQUIRE(iter.storage() == data_exp);
561 REQUIRE(iter.storage() != citer0.storage());
562 REQUIRE(iter.storage() != *data.snapshot());
565 REQUIRE( iter == iter.end() );
566 size_pre = iter.size();
567 REQUIRE( iter.dist_begin() ==
static_cast<diff_type
>(size_pre));
568 REQUIRE( iter.dist_end() == 0);
573 iter.insert(data2.cbegin(), data2.cbegin()+data2.size());
575 REQUIRE( iter.size() == size_pre+10 );
576 REQUIRE( iter == iter.end()-10 );
577 REQUIRE( iter.dist_begin() ==
static_cast<diff_type
>(size_pre));
578 REQUIRE( iter.dist_end() == 10);
580 storage_t data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
581 REQUIRE(iter.storage() == data_exp);
585 REQUIRE( iter == iter.end()-10 );
586 size_pre = iter.size();
590 REQUIRE( iter.size() == size_pre-10 );
591 REQUIRE( iter == iter.end() );
593 storage_t data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
594 REQUIRE(iter.storage() == data_exp);
598 size_pre = iter.size();
600 REQUIRE( iter == iter.begin() );
601 elem = iter.begin()[1];
603 REQUIRE( iter.size() == size_pre-1 );
604 REQUIRE( iter == iter.begin() );
605 REQUIRE( *iter == elem );
607 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
608 REQUIRE(iter.storage() == data_exp);
612 size_pre = iter.size();
613 REQUIRE( iter == iter.begin() );
614 elem = iter.end()[-1];
618 citer_type data2_iter = data2.cbegin();
619 iter.push_back(data2_iter[0]);
620 iter.push_back(data2_iter[1]);
621 iter.push_back(data2_iter[2]);
622 REQUIRE( iter.size() == size_pre+3 );
623 REQUIRE( iter == iter.end() );
624 REQUIRE( iter[-3] == data2_iter[0] );
625 REQUIRE( iter[-2] == data2_iter[1] );
626 REQUIRE( iter[-1] == data2_iter[2] );
629 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3 };
630 REQUIRE(iter.storage() == data_exp);
634 size_pre = iter.size();
635 REQUIRE( iter == iter.end() );
638 REQUIRE( iter.size() == size_pre-3 );
639 REQUIRE( iter == iter.end() );
641 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
642 REQUIRE(iter.storage() == data_exp);
646 size_pre = iter.size();
647 REQUIRE( iter == iter.end() );
649 value_type elem0 = iter.begin()[0];
650 iter.push_back( std::move(elem0));
653 value_type elem0 = iter.begin()[1];
654 iter.push_back( std::move(elem0));
657 value_type elem0 = iter.begin()[2];
658 iter.push_back( std::move(elem0));
660 REQUIRE( iter.size() == size_pre+3 );
661 REQUIRE( iter == iter.end() );
662 REQUIRE( iter[-3] == iter.begin()[0] );
663 REQUIRE( iter[-2] == iter.begin()[1] );
664 REQUIRE( iter[-1] == iter.begin()[2] );
666 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4 };
667 REQUIRE(iter.storage() == data_exp);
671 REQUIRE( iter == iter.end() );
676 REQUIRE( iter == iter.end() );
678 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
679 REQUIRE(iter.storage() == data_exp);
685 REQUIRE( iter == iter.begin()+5 );
686 REQUIRE( iter.dist_begin() == 5 );
688 size_pre = iter.size();
692 citer_type data2_iter = data2.cbegin();
693 iter.insert(data2_iter[0]);
694 iter.insert(data2_iter[1]);
695 iter.insert(data2_iter[2]);
696 REQUIRE( iter.size() == size_pre+3 );
697 REQUIRE( iter == iter.begin()+5 );
699 REQUIRE( iter[5] == data2_iter[2] );
700 REQUIRE( iter[6] == data2_iter[1] );
701 REQUIRE( iter[7] == data2_iter[0] );
704 storage_t data_exp = { 2, 3, 4, 5, 6, 3, 2, 1, 7, 8, 9 };
705 REQUIRE(iter.storage() == data_exp);
710 REQUIRE( iter == iter.begin()+5 );
711 size_pre = iter.size();
715 iter.insert(data2.cbegin(), data2.cbegin()+3);
717 REQUIRE( iter.size() == size_pre+3 );
718 REQUIRE( iter == iter.begin()+5 );
720 storage_t data_exp = { 2, 3, 4, 5, 6, 1, 2, 3, 3, 2, 1, 7, 8, 9 };
721 REQUIRE(iter.storage() == data_exp);
725 REQUIRE( iter == iter.begin()+5 );
726 size_pre = iter.size();
728 REQUIRE( iter.size() == size_pre-6 );
729 REQUIRE( iter == iter.begin()+5 );
731 storage_t data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
732 REQUIRE(iter.storage() == data_exp);
736 size_pre = iter.size();
737 REQUIRE( iter == iter.begin()+5 );
738 iter.emplace(
static_cast<uint64_t
>(2) );
739 iter.emplace(
static_cast<uint64_t
>(3) );
740 iter.emplace(
static_cast<uint64_t
>(4) );
741 REQUIRE( iter == iter.begin()+5 );
742 REQUIRE( iter[0] == 4 );
743 REQUIRE( iter[1] == 3 );
744 REQUIRE( iter[2] == 2 );
746 storage_t data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9 };
747 REQUIRE(iter.storage() == data_exp);
751 size_pre = iter.size();
752 REQUIRE( iter == iter.begin()+5 );
753 iter.emplace_back(
static_cast<uint64_t
>(2) );
754 iter.emplace_back(
static_cast<uint64_t
>(3) );
755 iter.emplace_back(
static_cast<uint64_t
>(4) );
756 REQUIRE( iter == iter.end() );
757 REQUIRE( iter[-1] == 4 );
758 REQUIRE( iter[-2] == 3 );
759 REQUIRE( iter[-3] == 2 );
761 storage_t data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9, 2, 3, 4 };
762 REQUIRE(iter.storage() == data_exp);
766 size_pre = iter.size();
767 REQUIRE( iter == iter.end() );
769 REQUIRE( iter == iter.end()-10 );
772 while( iter != iter.end() ) {
776 REQUIRE( iter.size() == size_pre - 10 );
779 storage_t data_exp = { 2, 3, 4, 5 };
780 REQUIRE(iter.storage() == data_exp);
785 REQUIRE( iter != data.cbegin() );
786 REQUIRE( iter.storage() != *data.snapshot() );
788 T data_exp = { 2, 3, 4, 5 };
789 REQUIRE(data != data_exp);
793 T data_exp = { 2, 3, 4, 5 };
794 REQUIRE(data == data_exp);
805 typedef typename T::iterator iter_type;
806 typedef typename T::const_iterator citer_type;
807 typedef typename T::difference_type diff_type;
809 printf(
"**** test_mutable_iterator_ops(___): %s\n", type_id.c_str());
813 iter_type begin = data.begin();
814 iter_type end = data.end();
815 diff_type data_size =
static_cast<diff_type
>(data.size());
816 REQUIRE( end - begin == data_size );
817 REQUIRE( end - data_size == begin );
818 REQUIRE( begin + data_size == end );
819 REQUIRE( *( end - data_size ) == *begin );
820 REQUIRE( *( begin + data_size ) == *end );
821 test_iterator_dereference<T, iter_type>(data.size(), begin, end);
829 iter_type begin = data.begin();
830 iter_type end = data.end();
831 citer_type cend = data.cend();
832 citer_type cbegin = data.cbegin();
834 test_iterator_arithmetic<T>(data.size(), begin, end);
835 test_iterator_arithmetic<T>(data.size(), cbegin, cend);
836 test_iterator_arithmetic<T>(data.size(), begin, cend);
837 test_iterator_arithmetic<T>(data.size(), cbegin, end);
857 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
858 REQUIRE(data == data_exp);
861 iter_type iter = data.end();
862 typename T::size_type size_pre = data.size();
863 typename T::value_type elem = iter[-2];
870 REQUIRE( data.size() == size_pre-1 );
871 REQUIRE( iter == data.end() );
872 REQUIRE( iter == data.begin()+size_pre-1 );
873 REQUIRE( iter[-1] == elem );
875 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
876 REQUIRE(data == data_exp);
880 REQUIRE( iter == data.end() );
881 size_pre = data.size();
885 iter = data.insert(iter, data2.cbegin(), data2.cbegin()+data2.size());
887 REQUIRE( data.size() == size_pre+10 );
888 REQUIRE( iter == data.end()-10 );
890 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
891 REQUIRE(data == data_exp);
895 REQUIRE( iter == data.end()-10 );
896 size_pre = data.size();
898 iter = data.erase(iter, iter+10);
900 REQUIRE( data.size() == size_pre-10 );
901 REQUIRE( iter == data.end() );
903 T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
904 REQUIRE(data == data_exp);
908 size_pre = data.size();
910 REQUIRE( iter == data.begin() );
912 iter = data.erase(iter);
913 REQUIRE( data.size() == size_pre-1 );
914 REQUIRE( iter == data.begin() );
915 REQUIRE( *iter == elem );
917 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
918 REQUIRE(data == data_exp);
922 size_pre = data.size();
923 REQUIRE( iter == data.begin() );
924 elem = data.end()[-1];
928 data.push_back(data2[0]);
929 data.push_back(data2[1]);
930 data.push_back(data2[2]);
932 REQUIRE( data.size() == size_pre+3 );
933 REQUIRE( iter == data.end() );
934 REQUIRE( iter[-3] == data2[0] );
935 REQUIRE( iter[-2] == data2[1] );
936 REQUIRE( iter[-1] == data2[2] );
939 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3 };
940 REQUIRE(data == data_exp);
944 size_pre = data.size();
945 REQUIRE( iter == data.end() );
947 iter = data.erase(iter, iter+3);
948 REQUIRE( data.size() == size_pre-3 );
949 REQUIRE( iter == data.end() );
951 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
952 REQUIRE(data == data_exp);
956 size_pre = data.size();
957 REQUIRE( iter == data.end() );
959 typename T::value_type elem0 = data.begin()[0];
960 data.push_back( std::move(elem0));
963 typename T::value_type elem0 = data.begin()[1];
964 data.push_back( std::move(elem0));
967 typename T::value_type elem0 = data.begin()[2];
968 data.push_back( std::move(elem0));
971 REQUIRE( data.size() == size_pre+3 );
972 REQUIRE( iter == data.end() );
973 REQUIRE( iter[-3] == data.begin()[0] );
974 REQUIRE( iter[-2] == data.begin()[1] );
975 REQUIRE( iter[-1] == data.begin()[2] );
977 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4 };
978 REQUIRE(data == data_exp);
982 REQUIRE( iter == data.end() );
984 iter = data.erase(iter);
985 iter = data.erase(iter);
986 iter = data.erase(iter);
987 REQUIRE( iter == data.end() );
989 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
990 REQUIRE(data == data_exp);
996 REQUIRE( iter == data.begin()+5 );
997 size_pre = data.size();
1001 iter = data.insert(iter, data2[0]);
1002 iter = data.insert(iter, data2[1]);
1003 iter = data.insert(iter, data2[2]);
1004 REQUIRE( data.size() == size_pre+3 );
1005 REQUIRE( iter == data.begin()+5 );
1006 iter = data.begin();
1007 REQUIRE( iter[5] == data2[2] );
1008 REQUIRE( iter[6] == data2[1] );
1009 REQUIRE( iter[7] == data2[0] );
1012 T data_exp = { 2, 3, 4, 5, 6, 3, 2, 1, 7, 8, 9 };
1013 REQUIRE(data == data_exp);
1018 REQUIRE( iter == data.begin()+5 );
1019 size_pre = data.size();
1023 iter = data.insert(iter, data2.cbegin(), data2.cbegin()+3);
1025 REQUIRE( data.size() == size_pre+3 );
1026 REQUIRE( iter == data.begin()+5 );
1028 T data_exp = { 2, 3, 4, 5, 6, 1, 2, 3, 3, 2, 1, 7, 8, 9 };
1029 REQUIRE(data == data_exp);
1033 REQUIRE( iter == data.begin()+5 );
1034 size_pre = data.size();
1035 iter = data.erase(iter, iter+6);
1036 REQUIRE( data.size() == size_pre-6 );
1037 REQUIRE( iter == data.begin()+5 );
1039 T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
1040 REQUIRE(data == data_exp);
1044 size_pre = data.size();
1045 REQUIRE( iter == data.begin()+5 );
1046 iter = data.emplace(iter,
static_cast<uint64_t
>(2) );
1047 iter = data.emplace(iter,
static_cast<uint64_t
>(3) );
1048 iter = data.emplace(iter,
static_cast<uint64_t
>(4) );
1050 REQUIRE( iter == data.begin()+5 );
1051 REQUIRE( iter[0] == 4 );
1052 REQUIRE( iter[1] == 3 );
1053 REQUIRE( iter[2] == 2 );
1055 T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9 };
1056 REQUIRE(data == data_exp);
1060 size_pre = data.size();
1061 REQUIRE( iter == data.begin()+5 );
1062 data.emplace_back(
static_cast<uint64_t
>(2) );
1063 data.emplace_back(
static_cast<uint64_t
>(3) );
1064 data.emplace_back(
static_cast<uint64_t
>(4) );
1066 REQUIRE( iter == data.end() );
1067 REQUIRE( iter[-1] == 4 );
1068 REQUIRE( iter[-2] == 3 );
1069 REQUIRE( iter[-3] == 2 );
1071 T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9, 2, 3, 4 };
1072 REQUIRE(data == data_exp);
1076 size_pre = data.size();
1077 REQUIRE( iter == data.end() );
1079 REQUIRE( iter == data.end()-10 );
1082 while( iter != data.end() ) {
1083 iter = data.erase(iter);
1086 REQUIRE( data.size() == size_pre - 10 );
1087 REQUIRE( iter == data.end() );
1090 T data_exp = { 2, 3, 4, 5 };
1091 REQUIRE(data == data_exp);
1102 REQUIRE(data == data2);
1103 REQUIRE(data == data3);
1114 test_citer_type_ops<T>(type_id);
1116 test_mutable_iterator_ops<T>(type_id);
1123 typedef typename T::size_type size_type;
1124 typedef typename T::const_iterator citer_type;
1125 typedef typename T::iterator iter_type;
1127 printf(
"**** test_cow_iterator_properties: %s\n", type_id.c_str());
1128 print_iterator_info<citer_type>(
"citer_type");
1129 print_iterator_info<iter_type>(
"iter_type");
1131 const size_type size0 = 100;
1134 REQUIRE(0 == data.get_allocator().memory_usage);
1135 REQUIRE(data.size() == 0);
1136 REQUIRE(data.capacity() == 0);
1137 REQUIRE(data.empty() ==
true);
1140 REQUIRE(0 != data.get_allocator().memory_usage);
1141 REQUIRE(data.size() == size0);
1142 REQUIRE(data.size() <= data.capacity());
1147 iter_type iter1 = data.begin();
1148 citer_type citer2 = iter1.immutable();
1149 citer_type citer3 = iter1.immutable().to_end();
1151 REQUIRE( iter1.is_begin() );
1152 REQUIRE( citer2.is_begin() );
1153 REQUIRE( citer3.is_end() );
1155 REQUIRE( iter1.dist_begin() == 0);
1156 REQUIRE( iter1.dist_end() == size0);
1157 REQUIRE( citer2.dist_begin() == 0);
1158 REQUIRE( citer2.dist_end() == size0);
1159 REQUIRE( citer3.dist_begin() == size0);
1160 REQUIRE( citer3.dist_end() == 0);
1162 REQUIRE( ( iter1 == citer2 ) ==
true);
1163 REQUIRE( ( citer2 == iter1 ) ==
true);
1166 REQUIRE( ( citer2 != iter1 ) ==
true);
1167 REQUIRE( ( iter1 != citer2 ) ==
true);
1168 REQUIRE( ( citer2 > iter1 ) ==
true);
1169 REQUIRE( ( citer2 >= iter1 ) ==
true);
1170 REQUIRE( ( iter1 < citer2 ) ==
true);
1171 REQUIRE( ( iter1 <= citer2 ) ==
true);
1172 REQUIRE( ( citer2 - iter1 ) == 1);
1173 REQUIRE( ( iter1 - citer2 ) == -1);
1174 REQUIRE( citer2.dist_begin() == 1);
1175 REQUIRE( citer2.dist_end() == size0-1);
1179 REQUIRE( ( iter1 != citer2 ) ==
true);
1180 REQUIRE( ( citer2 != iter1 ) ==
true);
1181 REQUIRE( ( iter1 > citer2 ) ==
true);
1182 REQUIRE( ( iter1 >= citer2 ) ==
true);
1183 REQUIRE( ( citer2 < iter1 ) ==
true);
1184 REQUIRE( ( citer2 <= iter1 ) ==
true);
1185 REQUIRE( ( iter1 - citer2 ) == 1);
1186 REQUIRE( ( citer2 - iter1 ) == -1);
1187 REQUIRE( iter1.dist_begin() == 1);
1188 REQUIRE( iter1.dist_end() == size0-1);
1189 REQUIRE( citer2.dist_begin() == 0);
1190 REQUIRE( citer2.dist_end() == size0);
1192 REQUIRE( ( iter1.end() == citer3 ) ==
true);
1193 REQUIRE( ( iter1.to_end() == citer3 ) ==
true);
1194 REQUIRE( iter1.is_end() );
1195 REQUIRE( citer3.is_end() );
1196 REQUIRE( iter1.dist_begin() == size0);
1197 REQUIRE( iter1.dist_end() == 0);
1201 citer_type c_begin0 = data.cbegin();
1207 printf(
"testing mutable non-const behavior.\n");
1208 citer_type c_begin1;
1210 iter_type m_begin1 = data.begin();
1211 c_begin1 = m_begin1.immutable();
1213 REQUIRE(*c_begin1 == *m_begin1);
1214 REQUIRE( c_begin1 == m_begin1);
1215 REQUIRE( ( c_begin1 - m_begin1 ) == 0);
1216 printf(
" 1st store: %s == %s, dist %u\n",
1217 to_decstring(*c_begin1,
',', 2).c_str(),
to_decstring(*m_begin1,
',', 2).c_str(), (
unsigned int)(c_begin1 - m_begin1));
1218 citer_type c_begin2;
1220 iter_type m_begin2 = data.begin();
1221 c_begin2 = m_begin2.immutable();
1223 REQUIRE(*c_begin2 == *m_begin2);
1224 REQUIRE( c_begin2 == m_begin2);
1225 REQUIRE( ( c_begin2 - m_begin2 ) == 0);
1226 printf(
" 2nd store: %s == %s, dist %u\n",
1227 to_decstring(*c_begin2,
',', 2).c_str(),
to_decstring(*m_begin2,
',', 2).c_str(), (
unsigned int)(c_begin2 - m_begin2));
1229 REQUIRE(*c_begin2 == *c_begin1);
1230 REQUIRE( c_begin2 != c_begin1);
1231 REQUIRE( ( c_begin2 - c_begin1 ) != 0);
1232 printf(
"2nd -> 1st store: %s == %s, dist %u\n",
1233 to_decstring(*c_begin2,
',', 2).c_str(),
to_decstring(*c_begin1,
',', 2).c_str(), (
unsigned int)(c_begin2 - c_begin1));
1235 m_begin2.write_back();
1238 citer_type c_begin2b = data.cbegin();
1239 REQUIRE(*c_begin2 == *c_begin2b);
1240 REQUIRE( c_begin2 == c_begin2b);
1241 REQUIRE( ( c_begin2 - c_begin2b ) == 0);
1242 printf(
"2nd -> cow == cbegin: %s == %s, dist %u\n",
1243 to_decstring(*c_begin2,
',', 2).c_str(),
to_decstring(*c_begin2b,
',', 2).c_str(), (
unsigned int)(c_begin2 - c_begin2b));
1244 printf(
"2nd -> 1st : %s == %s, dist %u\n",
1245 to_decstring(*c_begin1,
',', 2).c_str(),
to_decstring(*c_begin2,
',', 2).c_str(), (
unsigned int)(c_begin1 - c_begin2));
1247 m_begin1.write_back();
1250 citer_type c_begin1b = data.cbegin();
1251 printf(
"1st -> cow == cbegin: %s == %s, dist %u\n",
1252 to_decstring(*c_begin1,
',', 2).c_str(),
to_decstring(*c_begin1b,
',', 2).c_str(), (
unsigned int)(c_begin1 - c_begin1b));
1253 REQUIRE(*c_begin1 == *c_begin1b);
1254 REQUIRE( c_begin1 == c_begin1b);
1255 REQUIRE( ( c_begin1 - c_begin1b ) == 0);
1263 TEST_CASE(
"Iterator Test 00 - Inspect all Iterator Types",
"[datatype][std][vector][darray][cow_vector][cow_darray]" ) {
1264 test_00_inspect_iterator_types< std_vector_uint64_t >(
"std::vector<T>");
1265 test_00_inspect_iterator_types< jau_darray_uint64_t >(
"jau::darray<T>");
1266 test_00_inspect_iterator_types< jau_cow_vector_uint64_t >(
"jau::cow_vector<T>");
1267 test_00_inspect_iterator_types< jau_cow_darray_uint64_t >(
"jau::cow_darray<T>");
1270 TEST_CASE(
"STD Vector Test 01 - Validate Iterator and Index Operations",
"[datatype][std][vector]" ) {
1271 test_01_validate_iterator_ops< std_vector_uint64_t >(
"std::vector<T>");
1274 TEST_CASE(
"JAU DArray Test 02 - Validate Iterator and Index Operations",
"[datatype][jau][darray]" ) {
1275 test_01_validate_iterator_ops< jau_darray_uint64_t >(
"jau::darray<T>");
1278 TEST_CASE(
"JAU COW_Vector Test 11 - Validate Iterator Operations",
"[datatype][jau][cow_vector]" ) {
1279 test_01_validate_iterator_ops< jau_cow_vector_uint64_t >(
"jau::cow_vector<T>");
1281 test_01_cow_iterator_properties<jau_cow_vector_uint64_t>(
"jau::cow_vector<T>");
1284 TEST_CASE(
"JAU COW_DArray Test 21 - Validate Iterator Operations",
"[datatype][jau][cow_darray]" ) {
1285 test_01_validate_iterator_ops< jau_cow_darray_uint64_t >(
"jau::cow_darray<T>");
1287 test_01_cow_iterator_properties<jau_cow_darray_uint64_t>(
"jau::cow_darray<T>");