-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiter_test_original.cpp
3336 lines (2590 loc) · 113 KB
/
iter_test_original.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This test program verifies all of the container requirements for the Standard Library containers,
// including the four non-array sequence containers (deque, forward_list, list, vector), the four
// associative containers (map, multimap, multiset, and set), and the four unordered associative
// containers (unordered_map, unordered_multimap, unordered_multiset, and unordered_set).
//
// n3485 is the reference document for all language standard citations.
//
// A brief overview of the contents of this file:
//
// The first 650 lines or so of this file (everything up to the first use of DEFINE_TEST) are test
// utilities: stub allocators, comparers, and other kinds of types with which we can instantiate
// containers; test types that define a restricted set of operations; and a set of container traits
// classes that unify the interfaces for the containers so we can use a common set of tests for
// them (these traits also define a few useful properties for each container so we know what to
// test for each of them).
//
//
// For each operation (or collection of related operations) specified in the Container Requirements,
// we define a test using the DEFINE_TEST macro. These tests can be instantiated for any container.
// The DEFINE_TEST generates a set of typedefs (named c_{value_type}, where {value_type} is the type
// of object stored in that container) that can be used within the test, for brevity. In the test,
// we simply attempt to perform the operation being tested using a container instantiated with a
// value_type that provides only the capabilities required by the specification.
//
// If the requirements are different for some individual containers (e.g. vector::push_back requires
// more than the push_back member of other containers), a specialized test is written for those
// containers using the DEFINE_TEST_SPECIALIZATION macro.
//
// If a particular operation is not supported for a container (e.g., forward_list has no push_back),
// that test is disabled for that container using the NOT_SUPPORTED_SPECIALIZATION macro.
//
// If a particular test is failing for a container, the FAIL_SPECIALIZATION macro is used to stop
// that test from being run for that container (this macro has the same effect as the aforementioned
// NOT_SUPPORTED_SPECIALIZATION, but it is named differently so we can easily identify failing
// tests).
//
// Some tests, notably those that fail for all containers, are simply commented out. All failures
// are marked with the word "FAIL" in all capital letters, for easy searching.
//
// All test names start with "test_"
//
// For each group of related tests (generally divided by category as they are in the specification,
// e.g., General Container Requirements, Allocator-Aware Container Requirements, Sequence Container
// Requirements, etc.), we define a class template that instantiates all of the tests in that group.
// The names of these classes start with "check_". These classes will only instantiate tests for
// supported classes of containers. For example, check_all_sequence_requirements only instantiates
// the sequence container requirements tests for sequence containers.
//
// At the very bottom of the file there is a function template named verify_container that
// instantiates all of the check_ class templates for an individual container. This function
// template is instantiated once for each of the twelve containers being tested, by the verify_all
// function.
#include <cstddef>
#include <deque>
#include <forward_list>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <set>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <pmretvals.h>
//
//
// GENERAL UTILITIES
//
//
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, # __VA_ARGS__)
struct key { };
template <typename T>
struct faux_predicate
{
bool operator()(T const&) const { return false; }
};
template <typename T>
struct faux_compare
{
bool operator()(T const&, T const&) const { return false; }
};
template <typename T>
struct default_constructible_compare
{
default_constructible_compare() { }
default_constructible_compare(default_constructible_compare const&) { }
bool operator()(T const&, T const&) const { return false; }
private:
default_constructible_compare& operator=(default_constructible_compare const&);
};
template <typename T>
struct copy_constructible_compare
{
copy_constructible_compare(key) { }
copy_constructible_compare(copy_constructible_compare const&) { }
bool operator()(T const&, T const&) const { return false; }
private:
copy_constructible_compare();
copy_constructible_compare& operator=(copy_constructible_compare const&) { }
};
template <typename T>
struct faux_hash
{
std::size_t operator()(T const&) const { return 0; }
};
template <typename T>
struct default_constructible_hash
{
default_constructible_hash() { }
default_constructible_hash(default_constructible_hash const&) { }
bool operator()(T const&, T const&) const { return false; }
private:
default_constructible_hash& operator=(default_constructible_hash const&);
};
template <typename T>
struct copy_constructible_hash
{
copy_constructible_hash(key) { }
copy_constructible_hash(copy_constructible_hash const&) { }
std::size_t operator()(T const&) const { return 0; }
private:
copy_constructible_hash();
copy_constructible_hash& operator=(copy_constructible_hash const&) { }
};
//
//
// ITERATORS FOR TESTING RANGE MEMBERS
//
//
// Several functions have different requirements depending on the category of the iterator with
// which the function is called.
template <typename I, typename T>
struct input_iterator_base
{
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef std::input_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
input_iterator_base() { }
input_iterator_base(input_iterator_base const&) { }
input_iterator_base& operator=(input_iterator_base const&) { return *this; }
I& operator++() { return static_cast<I&>(*this); }
I operator++(int) { return static_cast<I&>(*this); }
friend bool operator==(I const&, I const&) { return true; }
friend bool operator!=(I const&, I const&) { return false; }
T& operator*() const { throw 0; }
T* operator->() const { throw 0; }
};
template <typename I, typename T>
struct forward_iterator_base : input_iterator_base<I, T>
{
typedef std::forward_iterator_tag iterator_category;
};
template <typename I, typename T>
struct bidirectional_iterator_base : forward_iterator_base<I, T>
{
typedef std::bidirectional_iterator_tag iterator_category;
I& operator--() { return *this; }
I operator--(int) { return *this; }
};
template <typename I, typename T>
struct random_access_iterator_base : bidirectional_iterator_base<I, T>
{
typedef std::random_access_iterator_tag iterator_category;
friend I operator+(I const&, std::ptrdiff_t) { return I(); }
friend I operator+(std::ptrdiff_t, I const&) { return I(); }
friend I operator-(I const&, std::ptrdiff_t) { return I(); }
friend std::ptrdiff_t operator-(I const&, I const&) { return 0; }
friend I& operator+=(I& x, std::ptrdiff_t) { return x; }
friend I& operator-=(I& x, std::ptrdiff_t) { return x; }
T& operator[](std::ptrdiff_t) { return this->_value; }
friend bool operator< (I const&, I const&) { return false; }
friend bool operator> (I const&, I const&) { return false; }
friend bool operator<=(I const&, I const&) { return true; }
friend bool operator>=(I const&, I const&) { return true; }
};
template <typename T> struct input_iterator : input_iterator_base <input_iterator <T>, T> { };
template <typename T> struct forward_iterator : forward_iterator_base <forward_iterator <T>, T> { };
template <typename T> struct bidirectional_iterator : bidirectional_iterator_base<bidirectional_iterator<T>, T> { };
template <typename T> struct random_access_iterator : random_access_iterator_base<random_access_iterator<T>, T> { };
//
//
// ALLOCATORS FOR TESTING ALLOCATOR CONCEPTS
//
//
// To verify the allocator-aware container requirements, we need two allocators--one that has
// propagate_on_container_move_assignment set to true; the other with it set to false. For all
// other tests, we simply use std::allocator.
template <typename T>
struct pocma_allocator
{
typedef T value_type;
pocma_allocator() { }
template <typename U>
pocma_allocator(pocma_allocator<U> const&) { }
value_type* allocate(std::size_t) { throw std::bad_alloc(); }
void deallocate(value_type*, std::size_t) { }
typedef std::true_type propagate_on_container_move_assignment;
friend bool operator==(pocma_allocator const&, pocma_allocator const&) { return true; }
friend bool operator!=(pocma_allocator const&, pocma_allocator const&) { return false; }
};
template <typename T>
struct non_pocma_allocator
{
typedef T value_type;
non_pocma_allocator() { }
template <typename U>
non_pocma_allocator(non_pocma_allocator<U> const&) { }
value_type* allocate(std::size_t) { throw std::bad_alloc(); }
void deallocate(value_type*, std::size_t) { }
typedef std::false_type propagate_on_container_move_assignment;
friend bool operator==(non_pocma_allocator const&, non_pocma_allocator const&) { return true; }
friend bool operator!=(non_pocma_allocator const&, non_pocma_allocator const&) { return false; }
};
//
//
// CONCEPT TEST TYPES
//
//
// These are test types that provide limited functionality and with which we can instantiate the
// Standard Library containers. The types that only model a single concept have their full name
// spelled out; types that model several concepts are abbreviated (e.g. DefaultConstructible +
// MoveInsertable is abbreviated as dc_mi).
struct emplace_argument
{
emplace_argument() { }
emplace_argument(key) { }
};
#define DEFINE_TYPE(name, dtor, default_ctor, copy_ctor, move_ctor, emplace_ctor, copy_assign, move_assign) \
class name \
{ \
public: name(key) { } \
private: dtor ~name() { } \
private: default_ctor name() { } \
private: copy_ctor name(name const&) { } \
private: move_ctor name(name&&) { } \
private: emplace_ctor name(emplace_argument&&) { } \
private: emplace_ctor name(emplace_argument&&, emplace_argument&&) { } \
private: emplace_ctor name(emplace_argument&&, emplace_argument&&, emplace_argument&&) { } \
private: copy_assign name& operator=(name const&) { return *this; } \
private: move_assign name& operator=(name&&) { return *this; } \
}
#define YES public:
// dtor default ctor copy ctor move ctor emplace ctor copy assign move assign
DEFINE_TYPE(erasable , YES , , , , , , );
DEFINE_TYPE(default_constructible, YES , YES , , , , , );
DEFINE_TYPE(copy_insertable , YES , , YES , YES , , , );
DEFINE_TYPE(move_insertable , YES , , , YES , , , );
DEFINE_TYPE(emplace_constructible, YES , , , , YES , , );
DEFINE_TYPE(copy_assignable , YES , , , , , YES , YES );
DEFINE_TYPE(move_assignable , YES , , , , , , YES );
DEFINE_TYPE(equality_comparable , YES , , , , , , );
DEFINE_TYPE(less_comparable , YES , , , , , , );
DEFINE_TYPE(ca_ci , YES , , YES , YES , , YES , YES );
DEFINE_TYPE(ci_ma , YES , , YES , YES , , , YES );
DEFINE_TYPE(dc_mi , YES , YES , , YES , , , );
DEFINE_TYPE(ec_ma_mi , YES , , , YES , YES , , YES );
DEFINE_TYPE(ec_mi , YES , , , YES , YES , , );
DEFINE_TYPE(ma_mi , YES , , , YES , , , YES );
#undef YES
bool operator==(equality_comparable const&, equality_comparable const&) { return true; }
bool operator< (less_comparable const&, less_comparable const&) { return false; }
//
//
// CONTAINER TRAITS
//
//
enum container_tag
{
tag_deque = (1 << 0),
tag_forward_list = (1 << 1),
tag_list = (1 << 2),
tag_vector = (1 << 3),
tag_map = (1 << 4),
tag_multimap = (1 << 5),
tag_set = (1 << 6),
tag_multiset = (1 << 7),
tag_unordered_map = (1 << 8),
tag_unordered_multimap = (1 << 9),
tag_unordered_set = (1 << 10),
tag_unordered_multiset = (1 << 11)
};
enum classification
{
c_is_reversible = (1 << 0),
c_is_optional = (1 << 1),
c_is_sequence = (1 << 2),
c_is_ordered_associative = (1 << 3),
c_is_unordered_associative = (1 << 4),
c_is_unique_associative = (1 << 5),
c_is_ordinary_sequence = (c_is_reversible | c_is_optional | c_is_sequence),
c_is_ordinary_unique_ordered_associative = (c_is_reversible | c_is_optional | c_is_ordered_associative | c_is_unique_associative),
c_is_ordinary_nonunique_ordered_associative = (c_is_reversible | c_is_optional | c_is_ordered_associative),
c_is_ordinary_unique_unordered_associative = (c_is_unordered_associative | c_is_unique_associative),
c_is_ordinary_nonunique_unordered_associative = (c_is_unordered_associative),
c_is_forward_list = (c_is_optional | c_is_sequence)
};
struct identity_bind_value
{
template <typename V>
struct bind_value { typedef V type; };
typedef emplace_argument emplace_argument_type;
template <typename V>
static V construct_value() { return V(key()); }
};
struct map_associative_bind_value
{
template <typename V>
struct bind_value { typedef std::pair<V const, V> type; };
typedef std::pair<emplace_argument, emplace_argument> emplace_argument_type;
template <typename V>
static std::pair<V, V> construct_value() { return std::pair<V, V>(key(), key()); }
};
template <template <typename, typename> class C>
struct sequence_bind_container
: identity_bind_value
{
template <typename V, typename A = std::allocator<V>>
struct bind_container { typedef C<V, A> type; };
};
template <template <typename, typename, typename, typename> class C>
struct ordered_map_associative_bind_container
: map_associative_bind_value
{
template <typename V, typename A = std::allocator<V>, typename P = faux_compare<V>>
struct bind_container
{
typedef typename bind_value<V>::type value_type;
typedef typename std::allocator_traits<A>::template rebind_alloc<value_type> alloc_type;
typedef C<V, V, P, alloc_type> type;
};
};
template <template <typename, typename, typename> class C>
struct ordered_set_associative_bind_container
: identity_bind_value
{
template <typename V, typename A = std::allocator<V>, typename P = faux_compare<V>>
struct bind_container
{
typedef C<V, P, A> type;
};
};
template <template <typename, typename, typename, typename, typename> class C>
struct unordered_map_associative_bind_container
: map_associative_bind_value
{
template <typename V, typename A = std::allocator<V>, typename H = faux_hash<V>, typename P = faux_compare<V>>
struct bind_container
{
typedef typename bind_value<V>::type value_type;
typedef typename std::allocator_traits<A>::template rebind_alloc<value_type> alloc_type;
typedef C<V, V, H, P, alloc_type> type;
};
};
template <template <typename, typename, typename, typename> class C>
struct unordered_set_associative_bind_container
: identity_bind_value
{
template <typename V, typename A = std::allocator<V>, typename H = faux_hash<V>, typename P = faux_compare<V>>
struct bind_container
{
typedef C<V, H, P, A> type;
};
};
template <container_tag Tag, classification Features>
struct container_traits_base
{
static container_tag const tag = Tag;
static classification const features = Features;
};
template <container_tag Tag, classification Features, template <typename, typename> class C>
struct sequence_traits_base
: container_traits_base<Tag, Features>,
sequence_bind_container<C> { };
template <container_tag Tag, classification Features, template <typename, typename, typename, typename> class C>
struct ordered_map_associative_container_base
: container_traits_base<Tag, Features>,
ordered_map_associative_bind_container<C> { };
template <container_tag Tag, classification Features, template <typename, typename, typename> class C>
struct ordered_set_associative_container_base
: container_traits_base<Tag, Features>,
ordered_set_associative_bind_container<C> { };
template <container_tag Tag, classification Features, template <typename, typename, typename, typename, typename> class C>
struct unordered_map_associative_container_base
: container_traits_base<Tag, Features>,
unordered_map_associative_bind_container<C> { };
template <container_tag Tag, classification Features, template <typename, typename, typename, typename> class C>
struct unordered_set_associative_container_base
: container_traits_base<Tag, Features>,
unordered_set_associative_bind_container<C> { };
template <container_tag>
struct container_traits;
template <>
struct container_traits<tag_deque>
: sequence_traits_base<
tag_deque,
c_is_ordinary_sequence,
std::deque
> { };
template <>
struct container_traits<tag_forward_list>
: sequence_traits_base<
tag_forward_list,
c_is_forward_list,
std::forward_list
> { };
template <>
struct container_traits<tag_list>
: sequence_traits_base<
tag_list,
c_is_ordinary_sequence,
std::list
> { };
template <>
struct container_traits<tag_vector>
: sequence_traits_base<
tag_vector,
c_is_ordinary_sequence,
std::vector
> { };
template <>
struct container_traits<tag_map>
: ordered_map_associative_container_base<
tag_map,
c_is_ordinary_unique_ordered_associative,
std::map
> { };
template <>
struct container_traits<tag_multimap>
: ordered_map_associative_container_base<
tag_multimap,
c_is_ordinary_nonunique_ordered_associative,
std::multimap
> { };
template <>
struct container_traits<tag_multiset>
: ordered_set_associative_container_base<
tag_multiset,
c_is_ordinary_nonunique_ordered_associative,
std::multiset
> { };
template <>
struct container_traits<tag_set>
: ordered_set_associative_container_base<
tag_set,
c_is_ordinary_unique_ordered_associative,
std::set
> { };
template <>
struct container_traits<tag_unordered_map>
: unordered_map_associative_container_base<
tag_unordered_map,
c_is_ordinary_unique_unordered_associative,
std::unordered_map
> { };
template <>
struct container_traits<tag_unordered_multimap>
: unordered_map_associative_container_base<
tag_unordered_multimap,
c_is_ordinary_nonunique_unordered_associative,
std::unordered_multimap
> { };
template <>
struct container_traits<tag_unordered_multiset>
: unordered_set_associative_container_base<
tag_unordered_multiset,
c_is_ordinary_nonunique_unordered_associative,
std::unordered_multiset
> { };
template <>
struct container_traits<tag_unordered_set>
: unordered_set_associative_container_base<
tag_unordered_set,
c_is_ordinary_unique_unordered_associative,
std::unordered_set
> { };
//
//
// TEST GENERATORS
//
//
#define GENERATE_CONTAINER_TYPEDEFS(name, opt_typename) \
typedef opt_typename Traits::template bind_container<name>::type c_of_ ## name; \
typedef opt_typename Traits::template bind_value <name>::type v_of_ ## name;
#define GENERATE_ALL_CONTAINER_TYPEDEFS(unused, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(erasable, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(default_constructible, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(copy_insertable, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(move_insertable, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(emplace_constructible, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(copy_assignable, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(move_assignable, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(equality_comparable, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(less_comparable, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(ca_ci, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(ci_ma, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(dc_mi, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(ec_ma_mi, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(ec_mi, opt_typename) \
GENERATE_CONTAINER_TYPEDEFS(ma_mi, opt_typename)
#define DEFINE_TEST_IMPL(name, opt_typename, template_parameters, specialization, preface_text, ...) \
template <template_parameters> \
struct name specialization \
{ \
preface_text \
typedef container_traits<Tag> Traits; \
\
name() \
{ \
GENERATE_ALL_CONTAINER_TYPEDEFS(unused, opt_typename); \
__VA_ARGS__ \
} \
}
#define DEFINE_TEST(name, ...) \
DEFINE_TEST_IMPL( \
/* name */ name, \
/* opt_typename */ typename, \
/* template_parameters */ container_tag Tag, \
/* specialization */ /* empty */, \
/* preface_text */ /* empty */, \
/* ... */ __VA_ARGS__)
#define DEFINE_TEST_SPECIALIZATION(name, specialized_tag, ...) \
DEFINE_TEST_IMPL( \
/* name */ name, \
/* opt_typename */ /* empty */, \
/* template_parameters */ /* empty */, \
/* specialization */ <specialized_tag>, \
/* preface_text */ static container_tag const Tag = specialized_tag;, \
/* ... */ __VA_ARGS__)
// These macros prevent the test named 'name' from being run for the container specified by the
// 'specialized_tag'. The FAIL_SPECIALIZATION macro is intended to be used for tests that are
// failing but which should pass. The NOT_SUPPORTED_SPECIALIZATION macro should be used for tests
// that do not pass because the container is specified as not supporting the operation being tested.
#define FAIL_SPECIALIZATION(name, specialized_tag) \
DEFINE_TEST_SPECIALIZATION(name, specialized_tag, { })
#define NOT_SUPPORTED_SPECIALIZATION(name, specialized_tag) \
DEFINE_TEST_SPECIALIZATION(name, specialized_tag, { })
//
//
// CONTAINER REQUIREMENTS (23.2.1[container.requirements.general]/Table 96)
//
//
DEFINE_TEST(test_container_typedefs,
{
// X::value_type, X::reference, X::const_reference
{
STATIC_ASSERT(std::is_same<v_of_erasable , typename c_of_erasable::value_type >::value);
STATIC_ASSERT(std::is_same<v_of_erasable& , typename c_of_erasable::reference >::value);
STATIC_ASSERT(std::is_same<v_of_erasable const&, typename c_of_erasable::const_reference>::value);
}
// X::iterator
{
STATIC_ASSERT(std::is_same<
v_of_erasable,
typename std::iterator_traits<typename c_of_erasable::iterator>::value_type
>::value);
STATIC_ASSERT(std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<typename c_of_erasable::iterator>::iterator_category
>::value);
STATIC_ASSERT(std::is_convertible<
typename c_of_erasable::iterator,
typename c_of_erasable::const_iterator
>::value);
}
// X::const_iterator
{
STATIC_ASSERT(std::is_same<
v_of_erasable,
typename std::iterator_traits<typename c_of_erasable::iterator>::value_type
>::value);
STATIC_ASSERT(std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<typename c_of_erasable::const_iterator>::iterator_category
>::value);
}
// X::difference_type
{
STATIC_ASSERT(std::is_signed<typename c_of_erasable::difference_type
>::value);
STATIC_ASSERT(std::is_same<
typename c_of_erasable::difference_type,
typename std::iterator_traits<typename c_of_erasable::iterator>::difference_type
>::value);
STATIC_ASSERT(std::is_same<
typename c_of_erasable::difference_type,
typename std::iterator_traits<typename c_of_erasable::const_iterator>::difference_type
>::value);
}
// X::size_type
{
STATIC_ASSERT(std::is_unsigned<typename c_of_erasable::size_type
>::value);
// Note: This check is overly strict:
STATIC_ASSERT(std::is_same<
typename c_of_erasable::size_type,
typename std::make_unsigned<typename c_of_erasable::difference_type>::type
>::value);
}
});
DEFINE_TEST(test_container_default_constructor,
{
// X u; and X()
// [No Requires clause]
c_of_erasable a;
(c_of_erasable());
});
DEFINE_TEST(test_container_copy_constructor,
{
// X(a), X u(a), and X u = a
// Requires: T is CopyInsertable into X
c_of_copy_insertable a;
(c_of_copy_insertable(a));
c_of_copy_insertable u0(a);
c_of_copy_insertable u1 = a;
});
DEFINE_TEST(test_container_move_constructor,
{
// X u(rv) and X u = rv
// [No Requires clause]
c_of_erasable rv;
c_of_erasable u0(std::move(rv));
c_of_erasable u1 = std::move(u0);
});
DEFINE_TEST(test_container_begin_end,
{
// a.begin(), a.end(), a.cbegin(), a.cend()
// [No Requires clause]
c_of_erasable a;
c_of_erasable const b;
typename c_of_erasable::iterator it0(a.begin());
typename c_of_erasable::iterator it1(a.end());
typename c_of_erasable::const_iterator it2(a.cbegin());
typename c_of_erasable::const_iterator it3(a.cend());
typename c_of_erasable::const_iterator it4(b.begin());
typename c_of_erasable::const_iterator it5(b.end());
typename c_of_erasable::const_iterator it6(b.cbegin());
typename c_of_erasable::const_iterator it7(b.cend());
STATIC_ASSERT(std::is_same<decltype(a.begin()), typename c_of_erasable::iterator>::value);
STATIC_ASSERT(std::is_same<decltype(a.end() ), typename c_of_erasable::iterator>::value);
STATIC_ASSERT(std::is_same<decltype(a.cbegin()), typename c_of_erasable::const_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(a.cend() ), typename c_of_erasable::const_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(b.begin()), typename c_of_erasable::const_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(b.end() ), typename c_of_erasable::const_iterator>::value);
});
DEFINE_TEST(test_container_equality_comparison,
{
// a == b and a != b
// Requires: T is EqualityComparable
c_of_equality_comparable const a;
c_of_equality_comparable const b;
a == b;
a != b;
STATIC_ASSERT(std::is_convertible<decltype(a == b), bool>::value);
STATIC_ASSERT(std::is_convertible<decltype(a != b), bool>::value);
});
DEFINE_TEST(test_container_swap,
{
// a.swap(b) and swap(a, b)
// [No Requires clause]
c_of_erasable a;
c_of_erasable b;
a.swap(b);
swap(a, b);
STATIC_ASSERT(std::is_same<decltype(a.swap(b)), void>::value);
STATIC_ASSERT(std::is_same<decltype(swap(a, b)), void>::value);
});
DEFINE_TEST(test_container_size,
{
// a.size(), a.max_size(), and a.empty()
c_of_erasable const a;
a.size();
a.max_size();
a.empty();
STATIC_ASSERT(std::is_same<decltype(a.size()), typename c_of_erasable::size_type>::value);
STATIC_ASSERT(std::is_same<decltype(a.max_size()), typename c_of_erasable::size_type>::value);
STATIC_ASSERT(std::is_convertible<decltype(a.empty()), bool>::value);
});
DEFINE_TEST_SPECIALIZATION(test_container_size, tag_forward_list,
{
// a.max_size(), and a.empty() [forward_list has no size() member]
c_of_erasable const a;
a.max_size();
a.empty();
STATIC_ASSERT(std::is_same<decltype(a.max_size()), typename c_of_erasable::size_type>::value);
STATIC_ASSERT(std::is_convertible<decltype(a.empty()), bool>::value);
});
template <container_tag Tag>
void check_all_container_requirements()
{
test_container_typedefs <Tag>();
test_container_default_constructor <Tag>();
test_container_copy_constructor <Tag>();
test_container_move_constructor <Tag>();
// Move Assignment is verified in the Allocator-Aware Container Requirements
test_container_begin_end <Tag>();
test_container_equality_comparison <Tag>();
test_container_swap <Tag>();
// Copy Assignment is verified in the Allocator-Aware Container Requirements
test_container_size <Tag>();
};
//
//
// REVERSIBLE CONTAINER REQUIREMENTS (23.2.1[container.requirements.general]/Table 97)
//
//
DEFINE_TEST(test_reversible_typedefs,
{
// X::reverse_iterator
{
STATIC_ASSERT(std::is_same<
typename std::iterator_traits<typename c_of_erasable::reverse_iterator>::value_type,
typename c_of_erasable::value_type
>::value);
STATIC_ASSERT(std::is_same<
typename c_of_erasable::reverse_iterator,
std::reverse_iterator<typename c_of_erasable::iterator>
>::value);
}
// X::const_reverse_iterator
{
STATIC_ASSERT(std::is_same<
typename std::iterator_traits<typename c_of_erasable::const_reverse_iterator>::value_type,
typename c_of_erasable::value_type
>::value);
STATIC_ASSERT(std::is_same<
typename c_of_erasable::const_reverse_iterator,
std::reverse_iterator<typename c_of_erasable::const_iterator>
>::value);
}
});
DEFINE_TEST(test_reversible_rbegin_rend,
{
// a.rbegin(), a.rend(), a.crbegin(), a.crend()
c_of_erasable a;
c_of_erasable const b;
typename c_of_erasable::reverse_iterator it0(a.rbegin());
typename c_of_erasable::reverse_iterator it1(a.rend());
typename c_of_erasable::const_reverse_iterator it2(a.crbegin());
typename c_of_erasable::const_reverse_iterator it3(a.crend());
typename c_of_erasable::const_reverse_iterator it4(b.rbegin());
typename c_of_erasable::const_reverse_iterator it5(b.rend());
typename c_of_erasable::const_reverse_iterator it6(b.crbegin());
typename c_of_erasable::const_reverse_iterator it7(b.crend());
STATIC_ASSERT(std::is_same<decltype(a.rbegin()), typename c_of_erasable::reverse_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(a.rend() ), typename c_of_erasable::reverse_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(a.crbegin()), typename c_of_erasable::const_reverse_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(a.crend() ), typename c_of_erasable::const_reverse_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(b.rbegin()), typename c_of_erasable::const_reverse_iterator>::value);
STATIC_ASSERT(std::is_same<decltype(b.rend() ), typename c_of_erasable::const_reverse_iterator>::value);
});
template <container_tag Tag, bool = (container_traits<Tag>::features & c_is_reversible) != 0>
struct check_all_reversible_requirements
{
check_all_reversible_requirements()
{
test_reversible_typedefs <Tag>();
test_reversible_rbegin_rend<Tag>();
}
};
template <container_tag Tag>
struct check_all_reversible_requirements<Tag, false> { };
//
//
// OPTIONAL CONTAINER OPERATIONS (23.2.1[container.requirements.general]/Table 98)
//
//
DEFINE_TEST(test_optional_relational_comparison,
{
// a < b; a > b; a <= b; a >= b
// Requires: < is defined for values of T. < is a total ordering relationship.
//
// SPEC: This is listed as a precondition; it should probably be a Requires.
c_of_less_comparable const a;
c_of_less_comparable const b;
a < b;
a > b;
a <= b;
a >= b;
STATIC_ASSERT(std::is_convertible<decltype(a < b), bool>::value);