llvm-project
238 строк · 6.0 Кб
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 set
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::set<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::set<int>::iterator i;70i = m.begin();71std::set<int>::const_iterator k = i;72assert(i == k);73for (int j = 1; j <= static_cast<int>(m.size()); ++j, ++i)74assert(*i == j);75assert(i == m.end());76for (int j = static_cast<int>(m.size()); j >= 1; --j) {77--i;78assert(*i == j);79}80assert(i == m.begin());81}82{83typedef int V;84V ar[] =85{861,871,881,892,902,912,923,933,943,954,964,974,985,995,1005,1016,1026,1036,1047,1057,1067,1078,1088,1098110};111const std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));112assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());113assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());114assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());115assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());116std::set<int>::const_iterator i;117i = m.begin();118for (int j = 1; j <= static_cast<int>(m.size()); ++j, ++i)119assert(*i == j);120assert(i == m.end());121for (int j = static_cast<int>(m.size()); j >= 1; --j) {122--i;123assert(*i == j);124}125assert(i == m.begin());126}127#if TEST_STD_VER >= 11128{129typedef int V;130V ar[] =131{1321,1331,1341,1352,1362,1372,1383,1393,1403,1414,1424,1434,1445,1455,1465,1476,1486,1496,1507,1517,1527,1538,1548,1558156};157std::set<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));158assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());159assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());160std::set<int, std::less<int>, min_allocator<int>>::iterator i;161i = m.begin();162std::set<int, std::less<int>, min_allocator<int>>::const_iterator k = i;163assert(i == k);164for (int j = 1; j <= static_cast<int>(m.size()); ++j, ++i)165assert(*i == j);166assert(i == m.end());167for (int j = static_cast<int>(m.size()); j >= 1; --j) {168--i;169assert(*i == j);170}171assert(i == m.begin());172}173{174typedef int V;175V ar[] =176{1771,1781,1791,1802,1812,1822,1833,1843,1853,1864,1874,1884,1895,1905,1915,1926,1936,1946,1957,1967,1977,1988,1998,2008201};202const std::set<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));203assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());204assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());205assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());206assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());207std::set<int, std::less<int>, min_allocator<int>>::const_iterator i;208i = m.begin();209for (int j = 1; j <= static_cast<int>(m.size()); ++j, ++i)210assert(*i == j);211assert(i == m.end());212for (int j = static_cast<int>(m.size()); j >= 1; --j) {213--i;214assert(*i == j);215}216assert(i == m.begin());217}218#endif219#if TEST_STD_VER > 11220{ // N3644 testing221typedef std::set<int> C;222C::iterator ii1{}, ii2{};223C::iterator ii4 = ii1;224C::const_iterator cii{};225assert ( ii1 == ii2 );226assert ( ii1 == ii4 );227
228assert (!(ii1 != ii2 ));229
230assert ( (ii1 == cii ));231assert ( (cii == ii1 ));232assert (!(ii1 != cii ));233assert (!(cii != ii1 ));234}235#endif236
237return 0;238}
239