• 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 // <vector>
12 
13 // template <class T, class Allocator, class U>
14 //   void erase(vector<T, Allocator>& c, const U& value);
15 
16 
17 #include <vector>
18 #include <optional>
19 
20 #include "test_macros.h"
21 #include "test_allocator.h"
22 #include "min_allocator.h"
23 
24 template <class S, class U>
25 void
test0(S s,U val,S expected)26 test0(S s,  U val, S expected)
27 {
28     ASSERT_SAME_TYPE(void, decltype(std::erase(s, val)));
29     std::erase(s, val);
30     assert(s == expected);
31 }
32 
33 template <class S>
test()34 void test()
35 {
36 
37     test0(S(), 1, S());
38 
39     test0(S({1}), 1, S());
40     test0(S({1}), 2, S({1}));
41 
42     test0(S({1,2}), 1, S({2}));
43     test0(S({1,2}), 2, S({1}));
44     test0(S({1,2}), 3, S({1,2}));
45     test0(S({1,1}), 1, S());
46     test0(S({1,1}), 3, S({1,1}));
47 
48     test0(S({1,2,3}), 1, S({2,3}));
49     test0(S({1,2,3}), 2, S({1,3}));
50     test0(S({1,2,3}), 3, S({1,2}));
51     test0(S({1,2,3}), 4, S({1,2,3}));
52 
53     test0(S({1,1,1}), 1, S());
54     test0(S({1,1,1}), 2, S({1,1,1}));
55     test0(S({1,1,2}), 1, S({2}));
56     test0(S({1,1,2}), 2, S({1,1}));
57     test0(S({1,1,2}), 3, S({1,1,2}));
58     test0(S({1,2,2}), 1, S({2,2}));
59     test0(S({1,2,2}), 2, S({1}));
60     test0(S({1,2,2}), 3, S({1,2,2}));
61 
62 //  Test cross-type erasure
63     using opt = std::optional<typename S::value_type>;
64     test0(S({1,2,1}), opt(),  S({1,2,1}));
65     test0(S({1,2,1}), opt(1), S({2}));
66     test0(S({1,2,1}), opt(2), S({1,1}));
67     test0(S({1,2,1}), opt(3), S({1,2,1}));
68 }
69 
main()70 int main()
71 {
72     test<std::vector<int>>();
73     test<std::vector<int, min_allocator<int>>> ();
74     test<std::vector<int, test_allocator<int>>> ();
75 
76     test<std::vector<long>>();
77     test<std::vector<double>>();
78 }
79