1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <vector>
11
12 // iterator begin();
13 // iterator end();
14 // const_iterator begin() const;
15 // const_iterator end() const;
16 // const_iterator cbegin() const;
17 // const_iterator cend() const;
18
19 #include <vector>
20 #include <cassert>
21 #include <iterator>
22
23 #include "test_macros.h"
24 #include "min_allocator.h"
25
26 struct A
27 {
28 int first;
29 int second;
30 };
31
main()32 int main()
33 {
34 {
35 typedef int T;
36 typedef std::vector<T> C;
37 C c;
38 C::iterator i = c.begin();
39 C::iterator j = c.end();
40 assert(std::distance(i, j) == 0);
41 assert(i == j);
42 }
43 {
44 typedef int T;
45 typedef std::vector<T> C;
46 const C c;
47 C::const_iterator i = c.begin();
48 C::const_iterator j = c.end();
49 assert(std::distance(i, j) == 0);
50 assert(i == j);
51 }
52 {
53 typedef int T;
54 typedef std::vector<T> C;
55 C c;
56 C::const_iterator i = c.cbegin();
57 C::const_iterator j = c.cend();
58 assert(std::distance(i, j) == 0);
59 assert(i == j);
60 assert(i == c.end());
61 }
62 {
63 typedef int T;
64 typedef std::vector<T> C;
65 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
66 C c(std::begin(t), std::end(t));
67 C::iterator i = c.begin();
68 assert(*i == 0);
69 ++i;
70 assert(*i == 1);
71 *i = 10;
72 assert(*i == 10);
73 assert(std::distance(c.begin(), c.end()) == 10);
74 }
75 {
76 typedef int T;
77 typedef std::vector<T> C;
78 C::iterator i;
79 C::const_iterator j;
80 (void) i;
81 (void) j;
82 }
83 #if TEST_STD_VER >= 11
84 {
85 typedef int T;
86 typedef std::vector<T, min_allocator<T>> C;
87 C c;
88 C::iterator i = c.begin();
89 C::iterator j = c.end();
90 assert(std::distance(i, j) == 0);
91 assert(i == j);
92 }
93 {
94 typedef int T;
95 typedef std::vector<T, min_allocator<T>> C;
96 const C c;
97 C::const_iterator i = c.begin();
98 C::const_iterator j = c.end();
99 assert(std::distance(i, j) == 0);
100 assert(i == j);
101 }
102 {
103 typedef int T;
104 typedef std::vector<T, min_allocator<T>> C;
105 C c;
106 C::const_iterator i = c.cbegin();
107 C::const_iterator j = c.cend();
108 assert(std::distance(i, j) == 0);
109 assert(i == j);
110 assert(i == c.end());
111 }
112 {
113 typedef int T;
114 typedef std::vector<T, min_allocator<T>> C;
115 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
116 C c(std::begin(t), std::end(t));
117 C::iterator i = c.begin();
118 assert(*i == 0);
119 ++i;
120 assert(*i == 1);
121 *i = 10;
122 assert(*i == 10);
123 assert(std::distance(c.begin(), c.end()) == 10);
124 }
125 {
126 typedef int T;
127 typedef std::vector<T, min_allocator<T>> C;
128 C::iterator i;
129 C::const_iterator j;
130 (void) i;
131 (void) j;
132 }
133 {
134 typedef A T;
135 typedef std::vector<T, min_allocator<T>> C;
136 C c = {A{1, 2}};
137 C::iterator i = c.begin();
138 i->first = 3;
139 C::const_iterator j = i;
140 assert(j->first == 3);
141 }
142 #endif
143 #if TEST_STD_VER > 11
144 { // N3644 testing
145 typedef std::vector<int> C;
146 C::iterator ii1{}, ii2{};
147 C::iterator ii4 = ii1;
148 C::const_iterator cii{};
149 assert ( ii1 == ii2 );
150 assert ( ii1 == ii4 );
151
152 assert (!(ii1 != ii2 ));
153
154 assert ( (ii1 == cii ));
155 assert ( (cii == ii1 ));
156 assert (!(ii1 != cii ));
157 assert (!(cii != ii1 ));
158 assert (!(ii1 < cii ));
159 assert (!(cii < ii1 ));
160 assert ( (ii1 <= cii ));
161 assert ( (cii <= ii1 ));
162 assert (!(ii1 > cii ));
163 assert (!(cii > ii1 ));
164 assert ( (ii1 >= cii ));
165 assert ( (cii >= ii1 ));
166 assert (cii - ii1 == 0);
167 assert (ii1 - cii == 0);
168 }
169 #endif
170 }
171