1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
12 // template <class T, class Hash, class Compare, class Allocator, class Predicate>
13 // void erase_if(unorderd_set<T, Hash, Compare, Allocator>& c, Predicate pred);
15 #include <unordered_set>
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
21 using Init
= std::initializer_list
<int>;
32 template <typename M
, typename Pred
>
34 test0(Init vals
, Pred p
, Init expected
)
37 ASSERT_SAME_TYPE(void, decltype(std::erase_if(s
, p
)));
39 M e
= make
<M
>(expected
);
40 assert((std::is_permutation(s
.begin(), s
.end(), e
.begin(), e
.end())));
47 auto is1
= [](auto v
) { return v
== 1;};
48 auto is2
= [](auto v
) { return v
== 2;};
49 auto is3
= [](auto v
) { return v
== 3;};
50 auto is4
= [](auto v
) { return v
== 4;};
51 auto True
= [](auto) { return true; };
52 auto False
= [](auto) { return false; };
54 test0
<S
>({}, is1
, {});
56 test0
<S
>({1}, is1
, {});
57 test0
<S
>({1}, is2
, {1});
59 test0
<S
>({1,2}, is1
, {2});
60 test0
<S
>({1,2}, is2
, {1});
61 test0
<S
>({1,2}, is3
, {1,2});
63 test0
<S
>({1,2,3}, is1
, {2,3});
64 test0
<S
>({1,2,3}, is2
, {1,3});
65 test0
<S
>({1,2,3}, is3
, {1,2});
66 test0
<S
>({1,2,3}, is4
, {1,2,3});
68 test0
<S
>({1,2,3}, True
, {});
69 test0
<S
>({1,2,3}, False
, {1,2,3});
74 test
<std::unordered_set
<int>>();
75 test
<std::unordered_set
<int, std::hash
<int>, std::equal_to
<int>, min_allocator
<int>>> ();
76 test
<std::unordered_set
<int, std::hash
<int>, std::equal_to
<int>, test_allocator
<int>>> ();
78 test
<std::unordered_set
<long>>();
79 test
<std::unordered_set
<double>>();