llvm-project
131 строка · 3.6 Кб
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// 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::multiset<int> M;25typedef int V;26typedef M::size_type I;27V ar[] =28{293,303,313,325,335,345,357,367,37738};39M m(ar, ar + sizeof(ar)/sizeof(ar[0]));40assert(m.size() == 9);41I i = m.erase(6);42assert(m.size() == 9);43assert(i == 0);44assert(*std::next(m.begin(), 0) == 3);45assert(*std::next(m.begin(), 1) == 3);46assert(*std::next(m.begin(), 2) == 3);47assert(*std::next(m.begin(), 3) == 5);48assert(*std::next(m.begin(), 4) == 5);49assert(*std::next(m.begin(), 5) == 5);50assert(*std::next(m.begin(), 6) == 7);51assert(*std::next(m.begin(), 7) == 7);52assert(*std::next(m.begin(), 8) == 7);53
54i = m.erase(5);55assert(m.size() == 6);56assert(i == 3);57assert(*std::next(m.begin(), 0) == 3);58assert(*std::next(m.begin(), 1) == 3);59assert(*std::next(m.begin(), 2) == 3);60assert(*std::next(m.begin(), 3) == 7);61assert(*std::next(m.begin(), 4) == 7);62assert(*std::next(m.begin(), 5) == 7);63
64i = m.erase(3);65assert(m.size() == 3);66assert(i == 3);67assert(*std::next(m.begin(), 0) == 7);68assert(*std::next(m.begin(), 1) == 7);69assert(*std::next(m.begin(), 2) == 7);70
71i = m.erase(7);72assert(m.size() == 0);73assert(i == 3);74}75#if TEST_STD_VER >= 1176{77typedef std::multiset<int, std::less<int>, min_allocator<int>> M;78typedef int V;79typedef M::size_type I;80V ar[] =81{823,833,843,855,865,875,887,897,90791};92M m(ar, ar + sizeof(ar)/sizeof(ar[0]));93assert(m.size() == 9);94I i = m.erase(6);95assert(m.size() == 9);96assert(i == 0);97assert(*std::next(m.begin(), 0) == 3);98assert(*std::next(m.begin(), 1) == 3);99assert(*std::next(m.begin(), 2) == 3);100assert(*std::next(m.begin(), 3) == 5);101assert(*std::next(m.begin(), 4) == 5);102assert(*std::next(m.begin(), 5) == 5);103assert(*std::next(m.begin(), 6) == 7);104assert(*std::next(m.begin(), 7) == 7);105assert(*std::next(m.begin(), 8) == 7);106
107i = m.erase(5);108assert(m.size() == 6);109assert(i == 3);110assert(*std::next(m.begin(), 0) == 3);111assert(*std::next(m.begin(), 1) == 3);112assert(*std::next(m.begin(), 2) == 3);113assert(*std::next(m.begin(), 3) == 7);114assert(*std::next(m.begin(), 4) == 7);115assert(*std::next(m.begin(), 5) == 7);116
117i = m.erase(3);118assert(m.size() == 3);119assert(i == 3);120assert(*std::next(m.begin(), 0) == 7);121assert(*std::next(m.begin(), 1) == 7);122assert(*std::next(m.begin(), 2) == 7);123
124i = m.erase(7);125assert(m.size() == 0);126assert(i == 3);127}128#endif129
130return 0;131}
132