llvm-project

Форк
0
274 строки · 7.9 Кб
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
// <map>
10

11
// class multimap
12

13
//       iterator begin();
14
// const_iterator begin() const;
15
//       iterator end();
16
// const_iterator end()   const;
17
//
18
//       reverse_iterator rbegin();
19
// const_reverse_iterator rbegin() const;
20
//       reverse_iterator rend();
21
// const_reverse_iterator rend()   const;
22
//
23
// const_iterator         cbegin()  const;
24
// const_iterator         cend()    const;
25
// const_reverse_iterator crbegin() const;
26
// const_reverse_iterator crend()   const;
27

28
#include <map>
29
#include <cassert>
30
#include <cstddef>
31

32
#include "test_macros.h"
33
#include "min_allocator.h"
34

35
int main(int, char**)
36
{
37
    {
38
        typedef std::pair<const int, double> V;
39
        V ar[] =
40
        {
41
            V(1, 1),
42
            V(1, 1.5),
43
            V(1, 2),
44
            V(2, 1),
45
            V(2, 1.5),
46
            V(2, 2),
47
            V(3, 1),
48
            V(3, 1.5),
49
            V(3, 2),
50
            V(4, 1),
51
            V(4, 1.5),
52
            V(4, 2),
53
            V(5, 1),
54
            V(5, 1.5),
55
            V(5, 2),
56
            V(6, 1),
57
            V(6, 1.5),
58
            V(6, 2),
59
            V(7, 1),
60
            V(7, 1.5),
61
            V(7, 2),
62
            V(8, 1),
63
            V(8, 1.5),
64
            V(8, 2)
65
        };
66
        std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
67
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
68
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
69
        std::multimap<int, double>::iterator i;
70
        i = m.begin();
71
        std::multimap<int, double>::const_iterator k = i;
72
        assert(i == k);
73
        for (int j = 1; j <= 8; ++j)
74
            for (double d = 1; d <= 2; d += .5, ++i)
75
            {
76
                assert(i->first == j);
77
                assert(i->second == d);
78
                i->second = 2.5;
79
                assert(i->second == 2.5);
80
            }
81
        assert(i == m.end());
82
        for (int j = 8; j >= 1; --j)
83
            for (double d = 1; d <= 2; d += .5)
84
            {
85
                --i;
86
                assert(i->first == j);
87
                assert(i->second == 2.5);
88
                i->second = d;
89
                assert(i->second == d);
90
            }
91
        assert(i == m.begin());
92
    }
93
    {
94
        typedef std::pair<const int, double> V;
95
        V ar[] =
96
        {
97
            V(1, 1),
98
            V(1, 1.5),
99
            V(1, 2),
100
            V(2, 1),
101
            V(2, 1.5),
102
            V(2, 2),
103
            V(3, 1),
104
            V(3, 1.5),
105
            V(3, 2),
106
            V(4, 1),
107
            V(4, 1.5),
108
            V(4, 2),
109
            V(5, 1),
110
            V(5, 1.5),
111
            V(5, 2),
112
            V(6, 1),
113
            V(6, 1.5),
114
            V(6, 2),
115
            V(7, 1),
116
            V(7, 1.5),
117
            V(7, 2),
118
            V(8, 1),
119
            V(8, 1.5),
120
            V(8, 2)
121
        };
122
        const std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
123
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
124
        assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
125
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
126
        assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
127
        std::multimap<int, double>::const_iterator i;
128
        i = m.begin();
129
        for (int j = 1; j <= 8; ++j)
130
            for (double d = 1; d <= 2; d += .5, ++i)
131
            {
132
                assert(i->first == j);
133
                assert(i->second == d);
134
            }
135
        assert(i == m.end());
136
        for (int j = 8; j >= 1; --j)
137
            for (double d = 2; d >= 1; d -= .5)
138
            {
139
                --i;
140
                assert(i->first == j);
141
                assert(i->second == d);
142
            }
143
        assert(i == m.begin());
144
    }
145
#if TEST_STD_VER >= 11
146
    {
147
        typedef std::pair<const int, double> V;
148
        V ar[] =
149
        {
150
            V(1, 1),
151
            V(1, 1.5),
152
            V(1, 2),
153
            V(2, 1),
154
            V(2, 1.5),
155
            V(2, 2),
156
            V(3, 1),
157
            V(3, 1.5),
158
            V(3, 2),
159
            V(4, 1),
160
            V(4, 1.5),
161
            V(4, 2),
162
            V(5, 1),
163
            V(5, 1.5),
164
            V(5, 2),
165
            V(6, 1),
166
            V(6, 1.5),
167
            V(6, 2),
168
            V(7, 1),
169
            V(7, 1.5),
170
            V(7, 2),
171
            V(8, 1),
172
            V(8, 1.5),
173
            V(8, 2)
174
        };
175
        std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
176
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
177
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
178
        std::multimap<int, double, std::less<int>, min_allocator<V>>::iterator i;
179
        i = m.begin();
180
        std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator k = i;
181
        assert(i == k);
182
        for (int j = 1; j <= 8; ++j)
183
            for (double d = 1; d <= 2; d += .5, ++i)
184
            {
185
                assert(i->first == j);
186
                assert(i->second == d);
187
                i->second = 2.5;
188
                assert(i->second == 2.5);
189
            }
190
        assert(i == m.end());
191
        for (int j = 8; j >= 1; --j)
192
            for (double d = 1; d <= 2; d += .5)
193
            {
194
                --i;
195
                assert(i->first == j);
196
                assert(i->second == 2.5);
197
                i->second = d;
198
                assert(i->second == d);
199
            }
200
        assert(i == m.begin());
201
    }
202
    {
203
        typedef std::pair<const int, double> V;
204
        V ar[] =
205
        {
206
            V(1, 1),
207
            V(1, 1.5),
208
            V(1, 2),
209
            V(2, 1),
210
            V(2, 1.5),
211
            V(2, 2),
212
            V(3, 1),
213
            V(3, 1.5),
214
            V(3, 2),
215
            V(4, 1),
216
            V(4, 1.5),
217
            V(4, 2),
218
            V(5, 1),
219
            V(5, 1.5),
220
            V(5, 2),
221
            V(6, 1),
222
            V(6, 1.5),
223
            V(6, 2),
224
            V(7, 1),
225
            V(7, 1.5),
226
            V(7, 2),
227
            V(8, 1),
228
            V(8, 1.5),
229
            V(8, 2)
230
        };
231
        const std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
232
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
233
        assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
234
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
235
        assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
236
        std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator i;
237
        i = m.begin();
238
        for (int j = 1; j <= 8; ++j)
239
            for (double d = 1; d <= 2; d += .5, ++i)
240
            {
241
                assert(i->first == j);
242
                assert(i->second == d);
243
            }
244
        assert(i == m.end());
245
        for (int j = 8; j >= 1; --j)
246
            for (double d = 2; d >= 1; d -= .5)
247
            {
248
                --i;
249
                assert(i->first == j);
250
                assert(i->second == d);
251
            }
252
        assert(i == m.begin());
253
    }
254
#endif
255
#if TEST_STD_VER > 11
256
    { // N3644 testing
257
        typedef std::multimap<int, double> C;
258
        C::iterator ii1{}, ii2{};
259
        C::iterator ii4 = ii1;
260
        C::const_iterator cii{};
261
        assert ( ii1 == ii2 );
262
        assert ( ii1 == ii4 );
263

264
        assert (!(ii1 != ii2 ));
265

266
        assert ( (ii1 == cii ));
267
        assert ( (cii == ii1 ));
268
        assert (!(ii1 != cii ));
269
        assert (!(cii != ii1 ));
270
    }
271
#endif
272

273
  return 0;
274
}
275

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.