llvm-project
246 строк · 6.3 Кб
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// <set>
10
11// class multiset
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 <set>29#include <cassert>30#include <cstddef>31
32#include "test_macros.h"33#include "min_allocator.h"34
35int main(int, char**)36{
37{38typedef int V;39V ar[] =40{411,421,431,442,452,462,473,483,493,504,514,524,535,545,555,566,576,586,597,607,617,628,638,64865};66std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));67assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());68assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());69std::multiset<int>::iterator i;70i = m.begin();71std::multiset<int>::const_iterator k = i;72assert(i == k);73for (int j = 1; j <= 8; ++j)74for (int n = 0; n < 3; ++n, ++i)75assert(*i == j);76assert(i == m.end());77for (int j = 8; j >= 1; --j)78for (int n = 0; n < 3; ++n) {79--i;80assert(*i == j);81}82assert(i == m.begin());83}84{85typedef int V;86V ar[] =87{881,891,901,912,922,932,943,953,963,974,984,994,1005,1015,1025,1036,1046,1056,1067,1077,1087,1098,1108,1118112};113const std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));114assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());115assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());116assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());117assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());118std::multiset<int>::const_iterator i;119i = m.begin();120for (int j = 1; j <= 8; ++j)121for (int k = 0; k < 3; ++k, ++i)122assert(*i == j);123assert(i == m.end());124for (int j = 8; j >= 1; --j)125for (int k = 0; k < 3; ++k) {126--i;127assert(*i == j);128}129assert(i == m.begin());130}131#if TEST_STD_VER >= 11132{133typedef int V;134V ar[] =135{1361,1371,1381,1392,1402,1412,1423,1433,1443,1454,1464,1474,1485,1495,1505,1516,1526,1536,1547,1557,1567,1578,1588,1598160};161std::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));162assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());163assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());164std::multiset<int, std::less<int>, min_allocator<int>>::iterator i;165i = m.begin();166std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator k = i;167assert(i == k);168for (int j = 1; j <= 8; ++j)169for (int n = 0; n < 3; ++n, ++i)170assert(*i == j);171assert(i == m.end());172for (int j = 8; j >= 1; --j)173for (int n = 0; n < 3; ++n) {174--i;175assert(*i == j);176}177assert(i == m.begin());178}179{180typedef int V;181V ar[] =182{1831,1841,1851,1862,1872,1882,1893,1903,1913,1924,1934,1944,1955,1965,1975,1986,1996,2006,2017,2027,2037,2048,2058,2068207};208const std::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));209assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());210assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());211assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());212assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());213std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator i;214i = m.begin();215for (int j = 1; j <= 8; ++j)216for (int k = 0; k < 3; ++k, ++i)217assert(*i == j);218assert(i == m.end());219for (int j = 8; j >= 1; --j)220for (int k = 0; k < 3; ++k) {221--i;222assert(*i == j);223}224assert(i == m.begin());225}226#endif227#if TEST_STD_VER > 11228{ // N3644 testing229typedef std::multiset<int> C;230C::iterator ii1{}, ii2{};231C::iterator ii4 = ii1;232C::const_iterator cii{};233assert ( ii1 == ii2 );234assert ( ii1 == ii4 );235
236assert (!(ii1 != ii2 ));237
238assert ( (ii1 == cii ));239assert ( (cii == ii1 ));240assert (!(ii1 != cii ));241assert (!(cii != ii1 ));242}243#endif244
245return 0;246}
247