xref: /llvm-project/libcxx/test/std/containers/associative/multimap/multimap.erasure/erase_if.pass.cpp (revision fb855eb941b6d740cc6560297d0b4d3201dcaf9f)
1f60c63c0SMarshall Clow //===----------------------------------------------------------------------===//
2f60c63c0SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f60c63c0SMarshall Clow //
7f60c63c0SMarshall Clow //===----------------------------------------------------------------------===//
831cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14, c++17
9f60c63c0SMarshall Clow 
10f60c63c0SMarshall Clow // <map>
11f60c63c0SMarshall Clow 
12f60c63c0SMarshall Clow // template <class Key, class T, class Compare, class Allocator, class Predicate>
133e895085SMarek Kurdej //   typename multimap<Key, T, Compare, Allocator>::size_type
143e895085SMarek Kurdej //   erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
15f60c63c0SMarshall Clow 
16f60c63c0SMarshall Clow #include <map>
17f60c63c0SMarshall Clow 
18f60c63c0SMarshall Clow #include "test_macros.h"
19f60c63c0SMarshall Clow #include "test_allocator.h"
20f60c63c0SMarshall Clow #include "min_allocator.h"
21f60c63c0SMarshall Clow 
22f60c63c0SMarshall Clow using Init = std::initializer_list<int>;
23f60c63c0SMarshall Clow template <typename M>
make(Init vals)24f60c63c0SMarshall Clow M make (Init vals)
25f60c63c0SMarshall Clow {
26f60c63c0SMarshall Clow     M ret;
27f60c63c0SMarshall Clow     for (int v : vals)
28bf7dc572SStephan T. Lavavej         ret.emplace(static_cast<typename M::key_type>(v), static_cast<typename M::mapped_type>(v + 10));
29f60c63c0SMarshall Clow     return ret;
30f60c63c0SMarshall Clow }
31f60c63c0SMarshall Clow 
32f60c63c0SMarshall Clow template <typename M, typename Pred>
test0(Init vals,Pred p,Init expected,std::size_t expected_erased_count)33*fb855eb9SMark de Wever void test0(Init vals, Pred p, Init expected, std::size_t expected_erased_count) {
34f60c63c0SMarshall Clow   M s = make<M>(vals);
353e895085SMarek Kurdej   ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));
363e895085SMarek Kurdej   assert(expected_erased_count == std::erase_if(s, p));
37f60c63c0SMarshall Clow   assert(s == make<M>(expected));
38f60c63c0SMarshall Clow }
39f60c63c0SMarshall Clow 
40f60c63c0SMarshall Clow template <typename S>
test()41f60c63c0SMarshall Clow void test()
42f60c63c0SMarshall Clow {
43f60c63c0SMarshall Clow     auto is1 = [](auto v) { return v.first == 1;};
44f60c63c0SMarshall Clow     auto is2 = [](auto v) { return v.first == 2;};
45f60c63c0SMarshall Clow     auto is3 = [](auto v) { return v.first == 3;};
46f60c63c0SMarshall Clow     auto is4 = [](auto v) { return v.first == 4;};
47f60c63c0SMarshall Clow     auto True  = [](auto) { return true; };
48f60c63c0SMarshall Clow     auto False = [](auto) { return false; };
49f60c63c0SMarshall Clow 
503e895085SMarek Kurdej     test0<S>({}, is1, {}, 0);
51f60c63c0SMarshall Clow 
523e895085SMarek Kurdej     test0<S>({1}, is1, {}, 1);
533e895085SMarek Kurdej     test0<S>({1}, is2, {1}, 0);
54f60c63c0SMarshall Clow 
553e895085SMarek Kurdej     test0<S>({1, 2}, is1, {2}, 1);
563e895085SMarek Kurdej     test0<S>({1, 2}, is2, {1}, 1);
573e895085SMarek Kurdej     test0<S>({1, 2}, is3, {1, 2}, 0);
583e895085SMarek Kurdej     test0<S>({1, 1}, is1, {}, 2);
593e895085SMarek Kurdej     test0<S>({1, 1}, is3, {1, 1}, 0);
60f60c63c0SMarshall Clow 
613e895085SMarek Kurdej     test0<S>({1, 2, 3}, is1, {2, 3}, 1);
623e895085SMarek Kurdej     test0<S>({1, 2, 3}, is2, {1, 3}, 1);
633e895085SMarek Kurdej     test0<S>({1, 2, 3}, is3, {1, 2}, 1);
643e895085SMarek Kurdej     test0<S>({1, 2, 3}, is4, {1, 2, 3}, 0);
65f60c63c0SMarshall Clow 
663e895085SMarek Kurdej     test0<S>({1, 1, 1}, is1, {}, 3);
673e895085SMarek Kurdej     test0<S>({1, 1, 1}, is2, {1, 1, 1}, 0);
683e895085SMarek Kurdej     test0<S>({1, 1, 2}, is1, {2}, 2);
693e895085SMarek Kurdej     test0<S>({1, 1, 2}, is2, {1, 1}, 1);
703e895085SMarek Kurdej     test0<S>({1, 1, 2}, is3, {1, 1, 2}, 0);
713e895085SMarek Kurdej     test0<S>({1, 2, 2}, is1, {2, 2}, 1);
723e895085SMarek Kurdej     test0<S>({1, 2, 2}, is2, {1}, 2);
733e895085SMarek Kurdej     test0<S>({1, 2, 2}, is3, {1, 2, 2}, 0);
74f60c63c0SMarshall Clow 
753e895085SMarek Kurdej     test0<S>({1, 2, 3}, True, {}, 3);
763e895085SMarek Kurdej     test0<S>({1, 2, 3}, False, {1, 2, 3}, 0);
77f60c63c0SMarshall Clow }
78f60c63c0SMarshall Clow 
main(int,char **)792df59c50SJF Bastien int main(int, char**)
80f60c63c0SMarshall Clow {
81f60c63c0SMarshall Clow     test<std::multimap<int, int>>();
82f60c63c0SMarshall Clow     test<std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>>> ();
83f60c63c0SMarshall Clow     test<std::multimap<int, int, std::less<int>, test_allocator<std::pair<const int, int>>>> ();
84f60c63c0SMarshall Clow 
85f60c63c0SMarshall Clow     test<std::multimap<long, short>>();
86f60c63c0SMarshall Clow     test<std::multimap<short, double>>();
872df59c50SJF Bastien 
882df59c50SJF Bastien   return 0;
89f60c63c0SMarshall Clow }
90