• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10 
11 // <unordered_set>
12 
13 // template <class T, class Hash, class Compare, class Allocator, class Predicate>
14 //   void erase_if(unorderd_set<T, Hash, Compare, Allocator>& c, Predicate pred);
15 
16 #include <unordered_set>
17 
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 
22 using Init = std::initializer_list<int>;
23 
24 template <typename M>
make(Init vals)25 M make (Init vals)
26 {
27     M ret;
28     for (int v : vals)
29         ret.insert(v);
30     return ret;
31 }
32 
33 template <typename M, typename Pred>
34 void
test0(Init vals,Pred p,Init expected)35 test0(Init vals, Pred p, Init expected)
36 {
37     M s = make<M> (vals);
38     ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p)));
39     std::erase_if(s, p);
40     M e = make<M>(expected);
41     assert((std::is_permutation(s.begin(), s.end(), e.begin(), e.end())));
42 }
43 
44 
45 template <typename S>
test()46 void test()
47 {
48     auto is1 = [](auto v) { return v == 1;};
49     auto is2 = [](auto v) { return v == 2;};
50     auto is3 = [](auto v) { return v == 3;};
51     auto is4 = [](auto v) { return v == 4;};
52     auto True  = [](auto) { return true; };
53     auto False = [](auto) { return false; };
54 
55     test0<S>({}, is1, {});
56 
57     test0<S>({1}, is1, {});
58     test0<S>({1}, is2, {1});
59 
60     test0<S>({1,2}, is1, {2});
61     test0<S>({1,2}, is2, {1});
62     test0<S>({1,2}, is3, {1,2});
63 
64     test0<S>({1,2,3}, is1, {2,3});
65     test0<S>({1,2,3}, is2, {1,3});
66     test0<S>({1,2,3}, is3, {1,2});
67     test0<S>({1,2,3}, is4, {1,2,3});
68 
69     test0<S>({1,2,3}, True,  {});
70     test0<S>({1,2,3}, False, {1,2,3});
71 }
72 
main()73 int main()
74 {
75     test<std::unordered_set<int>>();
76     test<std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>> ();
77     test<std::unordered_set<int, std::hash<int>, std::equal_to<int>, test_allocator<int>>> ();
78 
79     test<std::unordered_set<long>>();
80     test<std::unordered_set<double>>();
81 }
82