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 
10 // <list>
11 
12 // void remove(const value_type& value);
13 
14 #include <list>
15 #include <cassert>
16 
17 #include "min_allocator.h"
18 
19 struct S {
SS20     S(int i) : i_(new int(i)) {}
SS21     S(const S &rhs) : i_(new int(*rhs.i_)) {}
operator =S22     S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; }
~SS23     ~S () { delete i_; i_ = NULL; }
operator ==S24     bool operator == (const S &rhs) const { return *i_ == *rhs.i_; }
getS25     int get () const { return *i_; }
26     int *i_;
27     };
28 
29 
main()30 int main()
31 {
32     {
33     int a1[] = {1, 2, 3, 4};
34     int a2[] = {1, 2, 4};
35     std::list<int> c(a1, a1+4);
36     c.remove(3);
37     assert(c == std::list<int>(a2, a2+3));
38     }
39     {  // LWG issue #526
40     int a1[] = {1, 2, 1, 3, 5, 8, 11};
41     int a2[] = {   2,    3, 5, 8, 11};
42     std::list<int> c(a1, a1+7);
43     c.remove(c.front());
44     assert(c == std::list<int>(a2, a2+5));
45     }
46     {
47     int a1[] = {1, 2, 1, 3, 5, 8, 11, 1};
48     int a2[] = {   2,    3, 5, 8, 11   };
49     std::list<S> c;
50     for(int *ip = a1; ip < a1+8; ++ip)
51         c.push_back(S(*ip));
52     c.remove(c.front());
53     std::list<S>::const_iterator it = c.begin();
54     for(int *ip = a2; ip < a2+5; ++ip, ++it) {
55         assert ( it != c.end());
56         assert ( *ip == it->get());
57         }
58     assert ( it == c.end ());
59     }
60 #if __cplusplus >= 201103L
61     {
62     int a1[] = {1, 2, 3, 4};
63     int a2[] = {1, 2, 4};
64     std::list<int, min_allocator<int>> c(a1, a1+4);
65     c.remove(3);
66     assert((c == std::list<int, min_allocator<int>>(a2, a2+3)));
67     }
68 #endif
69 }
70