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 "min_allocator.h"
24 
25 struct A
26 {
27     int first;
28     int second;
29 };
30 
main()31 int main()
32 {
33     {
34         typedef int T;
35         typedef std::vector<T> C;
36         C c;
37         C::iterator i = c.begin();
38         C::iterator j = c.end();
39         assert(std::distance(i, j) == 0);
40         assert(i == j);
41     }
42     {
43         typedef int T;
44         typedef std::vector<T> C;
45         const C c;
46         C::const_iterator i = c.begin();
47         C::const_iterator j = c.end();
48         assert(std::distance(i, j) == 0);
49         assert(i == j);
50     }
51     {
52         typedef int T;
53         typedef std::vector<T> C;
54         C c;
55         C::const_iterator i = c.cbegin();
56         C::const_iterator j = c.cend();
57         assert(std::distance(i, j) == 0);
58         assert(i == j);
59         assert(i == c.end());
60     }
61     {
62         typedef int T;
63         typedef std::vector<T> C;
64         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
65         C c(std::begin(t), std::end(t));
66         C::iterator i = c.begin();
67         assert(*i == 0);
68         ++i;
69         assert(*i == 1);
70         *i = 10;
71         assert(*i == 10);
72         assert(std::distance(c.begin(), c.end()) == 10);
73     }
74     {
75         typedef int T;
76         typedef std::vector<T> C;
77         C::iterator i;
78         C::const_iterator j;
79     }
80 #if __cplusplus >= 201103L
81     {
82         typedef int T;
83         typedef std::vector<T, min_allocator<T>> C;
84         C c;
85         C::iterator i = c.begin();
86         C::iterator j = c.end();
87         assert(std::distance(i, j) == 0);
88         assert(i == j);
89     }
90     {
91         typedef int T;
92         typedef std::vector<T, min_allocator<T>> C;
93         const C c;
94         C::const_iterator i = c.begin();
95         C::const_iterator j = c.end();
96         assert(std::distance(i, j) == 0);
97         assert(i == j);
98     }
99     {
100         typedef int T;
101         typedef std::vector<T, min_allocator<T>> C;
102         C c;
103         C::const_iterator i = c.cbegin();
104         C::const_iterator j = c.cend();
105         assert(std::distance(i, j) == 0);
106         assert(i == j);
107         assert(i == c.end());
108     }
109     {
110         typedef int T;
111         typedef std::vector<T, min_allocator<T>> C;
112         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
113         C c(std::begin(t), std::end(t));
114         C::iterator i = c.begin();
115         assert(*i == 0);
116         ++i;
117         assert(*i == 1);
118         *i = 10;
119         assert(*i == 10);
120         assert(std::distance(c.begin(), c.end()) == 10);
121     }
122     {
123         typedef int T;
124         typedef std::vector<T, min_allocator<T>> C;
125         C::iterator i;
126         C::const_iterator j;
127     }
128     {
129         typedef A T;
130         typedef std::vector<T, min_allocator<T>> C;
131         C c = {A{1, 2}};
132         C::iterator i = c.begin();
133         i->first = 3;
134         C::const_iterator j = i;
135         assert(j->first == 3);
136     }
137 #endif
138 #if _LIBCPP_STD_VER > 11
139     { // N3644 testing
140         typedef std::vector<int> C;
141         C::iterator ii1{}, ii2{};
142         C::iterator ii4 = ii1;
143         C::const_iterator cii{};
144         assert ( ii1 == ii2 );
145         assert ( ii1 == ii4 );
146 
147         assert (!(ii1 != ii2 ));
148 
149         assert ( (ii1 == cii ));
150         assert ( (cii == ii1 ));
151         assert (!(ii1 != cii ));
152         assert (!(cii != ii1 ));
153         assert (!(ii1 <  cii ));
154         assert (!(cii <  ii1 ));
155         assert ( (ii1 <= cii ));
156         assert ( (cii <= ii1 ));
157         assert (!(ii1 >  cii ));
158         assert (!(cii >  ii1 ));
159         assert ( (ii1 >= cii ));
160         assert ( (cii >= ii1 ));
161         assert (cii - ii1 == 0);
162         assert (ii1 - cii == 0);
163     }
164 #endif
165 }
166