llvm-project
205 строк · 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// size_type erase(const key_type& k);
14
15#include <set>16#include <cassert>17
18#include "test_macros.h"19#include "min_allocator.h"20
21int main(int, char**)22{
23{24typedef std::set<int> M;25typedef int V;26typedef M::size_type I;27V ar[] =28{291,302,313,324,335,346,357,36837};38M m(ar, ar + sizeof(ar)/sizeof(ar[0]));39assert(m.size() == 8);40I i = m.erase(9);41assert(m.size() == 8);42assert(i == 0);43assert(*std::next(m.begin(), 0) == 1);44assert(*std::next(m.begin(), 1) == 2);45assert(*std::next(m.begin(), 2) == 3);46assert(*std::next(m.begin(), 3) == 4);47assert(*std::next(m.begin(), 4) == 5);48assert(*std::next(m.begin(), 5) == 6);49assert(*std::next(m.begin(), 6) == 7);50assert(*std::next(m.begin(), 7) == 8);51
52i = m.erase(4);53assert(m.size() == 7);54assert(i == 1);55assert(*std::next(m.begin(), 0) == 1);56assert(*std::next(m.begin(), 1) == 2);57assert(*std::next(m.begin(), 2) == 3);58assert(*std::next(m.begin(), 3) == 5);59assert(*std::next(m.begin(), 4) == 6);60assert(*std::next(m.begin(), 5) == 7);61assert(*std::next(m.begin(), 6) == 8);62
63i = m.erase(1);64assert(m.size() == 6);65assert(i == 1);66assert(*std::next(m.begin(), 0) == 2);67assert(*std::next(m.begin(), 1) == 3);68assert(*std::next(m.begin(), 2) == 5);69assert(*std::next(m.begin(), 3) == 6);70assert(*std::next(m.begin(), 4) == 7);71assert(*std::next(m.begin(), 5) == 8);72
73i = m.erase(8);74assert(m.size() == 5);75assert(i == 1);76assert(*std::next(m.begin(), 0) == 2);77assert(*std::next(m.begin(), 1) == 3);78assert(*std::next(m.begin(), 2) == 5);79assert(*std::next(m.begin(), 3) == 6);80assert(*std::next(m.begin(), 4) == 7);81
82i = m.erase(3);83assert(m.size() == 4);84assert(i == 1);85assert(*std::next(m.begin(), 0) == 2);86assert(*std::next(m.begin(), 1) == 5);87assert(*std::next(m.begin(), 2) == 6);88assert(*std::next(m.begin(), 3) == 7);89
90i = m.erase(6);91assert(m.size() == 3);92assert(i == 1);93assert(*std::next(m.begin(), 0) == 2);94assert(*std::next(m.begin(), 1) == 5);95assert(*std::next(m.begin(), 2) == 7);96
97i = m.erase(7);98assert(m.size() == 2);99assert(i == 1);100assert(*std::next(m.begin(), 0) == 2);101assert(*std::next(m.begin(), 1) == 5);102
103i = m.erase(2);104assert(m.size() == 1);105assert(i == 1);106assert(*std::next(m.begin(), 0) == 5);107
108i = m.erase(5);109assert(m.size() == 0);110assert(i == 1);111}112#if TEST_STD_VER >= 11113{114typedef std::set<int, std::less<int>, min_allocator<int>> M;115typedef int V;116typedef M::size_type I;117V ar[] =118{1191,1202,1213,1224,1235,1246,1257,1268127};128M m(ar, ar + sizeof(ar)/sizeof(ar[0]));129assert(m.size() == 8);130I i = m.erase(9);131assert(m.size() == 8);132assert(i == 0);133assert(*std::next(m.begin(), 0) == 1);134assert(*std::next(m.begin(), 1) == 2);135assert(*std::next(m.begin(), 2) == 3);136assert(*std::next(m.begin(), 3) == 4);137assert(*std::next(m.begin(), 4) == 5);138assert(*std::next(m.begin(), 5) == 6);139assert(*std::next(m.begin(), 6) == 7);140assert(*std::next(m.begin(), 7) == 8);141
142i = m.erase(4);143assert(m.size() == 7);144assert(i == 1);145assert(*std::next(m.begin(), 0) == 1);146assert(*std::next(m.begin(), 1) == 2);147assert(*std::next(m.begin(), 2) == 3);148assert(*std::next(m.begin(), 3) == 5);149assert(*std::next(m.begin(), 4) == 6);150assert(*std::next(m.begin(), 5) == 7);151assert(*std::next(m.begin(), 6) == 8);152
153i = m.erase(1);154assert(m.size() == 6);155assert(i == 1);156assert(*std::next(m.begin(), 0) == 2);157assert(*std::next(m.begin(), 1) == 3);158assert(*std::next(m.begin(), 2) == 5);159assert(*std::next(m.begin(), 3) == 6);160assert(*std::next(m.begin(), 4) == 7);161assert(*std::next(m.begin(), 5) == 8);162
163i = m.erase(8);164assert(m.size() == 5);165assert(i == 1);166assert(*std::next(m.begin(), 0) == 2);167assert(*std::next(m.begin(), 1) == 3);168assert(*std::next(m.begin(), 2) == 5);169assert(*std::next(m.begin(), 3) == 6);170assert(*std::next(m.begin(), 4) == 7);171
172i = m.erase(3);173assert(m.size() == 4);174assert(i == 1);175assert(*std::next(m.begin(), 0) == 2);176assert(*std::next(m.begin(), 1) == 5);177assert(*std::next(m.begin(), 2) == 6);178assert(*std::next(m.begin(), 3) == 7);179
180i = m.erase(6);181assert(m.size() == 3);182assert(i == 1);183assert(*std::next(m.begin(), 0) == 2);184assert(*std::next(m.begin(), 1) == 5);185assert(*std::next(m.begin(), 2) == 7);186
187i = m.erase(7);188assert(m.size() == 2);189assert(i == 1);190assert(*std::next(m.begin(), 0) == 2);191assert(*std::next(m.begin(), 1) == 5);192
193i = m.erase(2);194assert(m.size() == 1);195assert(i == 1);196assert(*std::next(m.begin(), 0) == 5);197
198i = m.erase(5);199assert(m.size() == 0);200assert(i == 1);201}202#endif203
204return 0;205}
206