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 // <unordered_map>
11f60c63c0SMarshall Clow
12f60c63c0SMarshall Clow // template <class Key, class T, class Hash, class Pred, class Allocator, class Predicate>
133e895085SMarek Kurdej // typename unordered_multimap<Key, T, Hash, Pred, Allocator>::size_type
143e895085SMarek Kurdej // erase_if(unordered_multimap<Key, T, Hash, Pred, Allocator>& c, Predicate pred);
15f60c63c0SMarshall Clow
16f60c63c0SMarshall Clow #include <unordered_map>
176ffa6a30SCasey Carter #include <algorithm>
18f60c63c0SMarshall Clow
19f60c63c0SMarshall Clow #include "test_macros.h"
20f60c63c0SMarshall Clow #include "test_allocator.h"
21f60c63c0SMarshall Clow #include "min_allocator.h"
22f60c63c0SMarshall Clow
23f60c63c0SMarshall Clow using Init = std::initializer_list<int>;
24f60c63c0SMarshall Clow template <typename M>
make(Init vals)25f60c63c0SMarshall Clow M make (Init vals)
26f60c63c0SMarshall Clow {
27f60c63c0SMarshall Clow M ret;
28f60c63c0SMarshall Clow for (int v : vals)
29bf7dc572SStephan T. Lavavej ret.emplace(static_cast<typename M::key_type>(v), static_cast<typename M::mapped_type>(v + 10));
30f60c63c0SMarshall Clow return ret;
31f60c63c0SMarshall Clow }
32f60c63c0SMarshall Clow
33f60c63c0SMarshall Clow template <typename M, typename Pred>
test0(Init vals,Pred p,Init expected,std::size_t expected_erased_count)34*fb855eb9SMark de Wever void test0(Init vals, Pred p, Init expected, std::size_t expected_erased_count) {
35f60c63c0SMarshall Clow M s = make<M>(vals);
363e895085SMarek Kurdej ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));
373e895085SMarek Kurdej assert(expected_erased_count == std::erase_if(s, p));
38f60c63c0SMarshall Clow M e = make<M>(expected);
39f60c63c0SMarshall Clow assert((std::is_permutation(s.begin(), s.end(), e.begin(), e.end())));
40f60c63c0SMarshall Clow }
41f60c63c0SMarshall Clow
42f60c63c0SMarshall Clow template <typename S>
test()43f60c63c0SMarshall Clow void test()
44f60c63c0SMarshall Clow {
45f60c63c0SMarshall Clow auto is1 = [](auto v) { return v.first == 1;};
46f60c63c0SMarshall Clow auto is2 = [](auto v) { return v.first == 2;};
47f60c63c0SMarshall Clow auto is3 = [](auto v) { return v.first == 3;};
48f60c63c0SMarshall Clow auto is4 = [](auto v) { return v.first == 4;};
49f60c63c0SMarshall Clow auto True = [](auto) { return true; };
50f60c63c0SMarshall Clow auto False = [](auto) { return false; };
51f60c63c0SMarshall Clow
523e895085SMarek Kurdej test0<S>({}, is1, {}, 0);
53f60c63c0SMarshall Clow
543e895085SMarek Kurdej test0<S>({1}, is1, {}, 1);
553e895085SMarek Kurdej test0<S>({1}, is2, {1}, 0);
56f60c63c0SMarshall Clow
573e895085SMarek Kurdej test0<S>({1, 2}, is1, {2}, 1);
583e895085SMarek Kurdej test0<S>({1, 2}, is2, {1}, 1);
593e895085SMarek Kurdej test0<S>({1, 2}, is3, {1, 2}, 0);
603e895085SMarek Kurdej test0<S>({1, 1}, is1, {}, 2);
613e895085SMarek Kurdej test0<S>({1, 1}, is3, {1, 1}, 0);
62f60c63c0SMarshall Clow
633e895085SMarek Kurdej test0<S>({1, 2, 3}, is1, {2, 3}, 1);
643e895085SMarek Kurdej test0<S>({1, 2, 3}, is2, {1, 3}, 1);
653e895085SMarek Kurdej test0<S>({1, 2, 3}, is3, {1, 2}, 1);
663e895085SMarek Kurdej test0<S>({1, 2, 3}, is4, {1, 2, 3}, 0);
67f60c63c0SMarshall Clow
683e895085SMarek Kurdej test0<S>({1, 1, 1}, is1, {}, 3);
693e895085SMarek Kurdej test0<S>({1, 1, 1}, is2, {1, 1, 1}, 0);
703e895085SMarek Kurdej test0<S>({1, 1, 2}, is1, {2}, 2);
713e895085SMarek Kurdej test0<S>({1, 1, 2}, is2, {1, 1}, 1);
723e895085SMarek Kurdej test0<S>({1, 1, 2}, is3, {1, 1, 2}, 0);
733e895085SMarek Kurdej test0<S>({1, 2, 2}, is1, {2, 2}, 1);
743e895085SMarek Kurdej test0<S>({1, 2, 2}, is2, {1}, 2);
753e895085SMarek Kurdej test0<S>({1, 2, 2}, is3, {1, 2, 2}, 0);
76f60c63c0SMarshall Clow
773e895085SMarek Kurdej test0<S>({1, 2, 3}, True, {}, 3);
783e895085SMarek Kurdej test0<S>({1, 2, 3}, False, {1, 2, 3}, 0);
79f60c63c0SMarshall Clow }
80f60c63c0SMarshall Clow
main(int,char **)812df59c50SJF Bastien int main(int, char**)
82f60c63c0SMarshall Clow {
83f60c63c0SMarshall Clow test<std::unordered_multimap<int, int>>();
84f60c63c0SMarshall Clow test<std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, int>>>> ();
85f60c63c0SMarshall Clow test<std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, test_allocator<std::pair<const int, int>>>> ();
86f60c63c0SMarshall Clow
87f60c63c0SMarshall Clow test<std::unordered_multimap<long, short>>();
88f60c63c0SMarshall Clow test<std::unordered_multimap<short, double>>();
892df59c50SJF Bastien
902df59c50SJF Bastien return 0;
91f60c63c0SMarshall Clow }
92