llvm-project
89 строк · 2.8 Кб
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// UNSUPPORTED: c++03, c++11, c++14, c++17
9
10// <map>
11
12// template <class Key, class T, class Compare, class Allocator, class Predicate>
13// typename multimap<Key, T, Compare, Allocator>::size_type
14// erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
15
16#include <map>17
18#include "test_macros.h"19#include "test_allocator.h"20#include "min_allocator.h"21
22using Init = std::initializer_list<int>;23template <typename M>24M make (Init vals)25{
26M ret;27for (int v : vals)28ret.emplace(static_cast<typename M::key_type>(v), static_cast<typename M::mapped_type>(v + 10));29return ret;30}
31
32template <typename M, typename Pred>33void test0(Init vals, Pred p, Init expected, std::size_t expected_erased_count) {34M s = make<M>(vals);35ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));36assert(expected_erased_count == std::erase_if(s, p));37assert(s == make<M>(expected));38}
39
40template <typename S>41void test()42{
43auto is1 = [](auto v) { return v.first == 1;};44auto is2 = [](auto v) { return v.first == 2;};45auto is3 = [](auto v) { return v.first == 3;};46auto is4 = [](auto v) { return v.first == 4;};47auto True = [](auto) { return true; };48auto False = [](auto) { return false; };49
50test0<S>({}, is1, {}, 0);51
52test0<S>({1}, is1, {}, 1);53test0<S>({1}, is2, {1}, 0);54
55test0<S>({1, 2}, is1, {2}, 1);56test0<S>({1, 2}, is2, {1}, 1);57test0<S>({1, 2}, is3, {1, 2}, 0);58test0<S>({1, 1}, is1, {}, 2);59test0<S>({1, 1}, is3, {1, 1}, 0);60
61test0<S>({1, 2, 3}, is1, {2, 3}, 1);62test0<S>({1, 2, 3}, is2, {1, 3}, 1);63test0<S>({1, 2, 3}, is3, {1, 2}, 1);64test0<S>({1, 2, 3}, is4, {1, 2, 3}, 0);65
66test0<S>({1, 1, 1}, is1, {}, 3);67test0<S>({1, 1, 1}, is2, {1, 1, 1}, 0);68test0<S>({1, 1, 2}, is1, {2}, 2);69test0<S>({1, 1, 2}, is2, {1, 1}, 1);70test0<S>({1, 1, 2}, is3, {1, 1, 2}, 0);71test0<S>({1, 2, 2}, is1, {2, 2}, 1);72test0<S>({1, 2, 2}, is2, {1}, 2);73test0<S>({1, 2, 2}, is3, {1, 2, 2}, 0);74
75test0<S>({1, 2, 3}, True, {}, 3);76test0<S>({1, 2, 3}, False, {1, 2, 3}, 0);77}
78
79int main(int, char**)80{
81test<std::multimap<int, int>>();82test<std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>>> ();83test<std::multimap<int, int, std::less<int>, test_allocator<std::pair<const int, int>>>> ();84
85test<std::multimap<long, short>>();86test<std::multimap<short, double>>();87
88return 0;89}
90