1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <list> |
10 | |
11 | // iterator begin(); |
12 | // iterator end(); |
13 | // const_iterator begin() const; |
14 | // const_iterator end() const; |
15 | // const_iterator cbegin() const; |
16 | // const_iterator cend() const; |
17 | |
18 | #include <list> |
19 | #include <cassert> |
20 | #include <iterator> |
21 | |
22 | #include "test_macros.h" |
23 | #include "min_allocator.h" |
24 | |
25 | struct A |
26 | { |
27 | int first; |
28 | int second; |
29 | }; |
30 | |
31 | int main(int, char**) |
32 | { |
33 | { |
34 | typedef int T; |
35 | typedef std::list<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::list<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::list<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::list<T> C; |
64 | const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
65 | C c(std::begin(arr: t), std::end(arr: 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::list<T> C; |
77 | C::iterator i; |
78 | C::const_iterator j; |
79 | } |
80 | #if TEST_STD_VER >= 11 |
81 | { |
82 | typedef int T; |
83 | typedef std::list<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::list<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::list<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::list<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::list<T, min_allocator<T>> C; |
125 | C::iterator i; |
126 | C::const_iterator j; |
127 | } |
128 | { |
129 | typedef A T; |
130 | typedef std::list<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 TEST_STD_VER > 11 |
139 | { |
140 | std::list<int>::iterator ii1{}, ii2{}; |
141 | std::list<int>::iterator ii4 = ii1; |
142 | std::list<int>::const_iterator cii{}; |
143 | assert ( ii1 == ii2 ); |
144 | assert ( ii1 == ii4 ); |
145 | |
146 | assert (!(ii1 != ii2 )); |
147 | |
148 | assert ( (ii1 == cii )); |
149 | assert ( (cii == ii1 )); |
150 | assert (!(ii1 != cii )); |
151 | assert (!(cii != ii1 )); |
152 | } |
153 | #endif |
154 | |
155 | |
156 | return 0; |
157 | } |
158 | |