Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / containers / sequences / forwardlist / forwardlist.ops / remove.pass.cpp
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 // <forward_list>
11
12 // void remove(const value_type& v);
13
14 #include <forward_list>
15 #include <iterator>
16 #include <cassert>
17
18 #include "min_allocator.h"
19
20 struct S {
21         S(int i) : i_(new int(i)) {}
22         S(const S &rhs) : i_(new int(*rhs.i_)) {}
23         S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; }
24         ~S () { delete i_; i_ = NULL; }
25         bool operator == (const S &rhs) const { return *i_ == *rhs.i_; }
26         int get () const { return *i_; }
27         int *i_;
28         };
29
30
31 int main()
32 {
33     {
34         typedef int T;
35         typedef std::forward_list<T> C;
36         const T t1[] = {0, 5, 5, 0, 0, 0, 5};
37         const T t2[] = {5, 5, 5};
38         C c1(std::begin(t1), std::end(t1));
39         C c2(std::begin(t2), std::end(t2));
40         c1.remove(0);
41         assert(c1 == c2);
42     }
43     {
44         typedef int T;
45         typedef std::forward_list<T> C;
46         const T t1[] = {0, 0, 0, 0};
47         C c1(std::begin(t1), std::end(t1));
48         C c2;
49         c1.remove(0);
50         assert(c1 == c2);
51     }
52     {
53         typedef int T;
54         typedef std::forward_list<T> C;
55         const T t1[] = {5, 5, 5};
56         const T t2[] = {5, 5, 5};
57         C c1(std::begin(t1), std::end(t1));
58         C c2(std::begin(t2), std::end(t2));
59         c1.remove(0);
60         assert(c1 == c2);
61     }
62     {
63         typedef int T;
64         typedef std::forward_list<T> C;
65         C c1;
66         C c2;
67         c1.remove(0);
68         assert(c1 == c2);
69     }
70     {
71         typedef int T;
72         typedef std::forward_list<T> C;
73         const T t1[] = {5, 5, 5, 0};
74         const T t2[] = {5, 5, 5};
75         C c1(std::begin(t1), std::end(t1));
76         C c2(std::begin(t2), std::end(t2));
77         c1.remove(0);
78         assert(c1 == c2);
79     }
80     {  // LWG issue #526
81     typedef int T;
82     typedef std::forward_list<T> C;
83     int t1[] = {1, 2, 1, 3, 5, 8, 11};
84     int t2[] = {   2,    3, 5, 8, 11};
85     C c1(std::begin(t1), std::end(t1));
86     C c2(std::begin(t2), std::end(t2));
87     c1.remove(c1.front());
88     assert(c1 == c2);
89     }
90     {
91     typedef S T;
92     typedef std::forward_list<T> C;
93     int t1[] = {1, 2, 1, 3, 5, 8, 11, 1};
94     int t2[] = {   2,    3, 5, 8, 11   };
95     C c;
96     for(int *ip = std::end(t1); ip != std::begin(t1);)
97         c.push_front(S(*--ip));
98     c.remove(c.front());
99     C::const_iterator it = c.begin();
100     for(int *ip = std::begin(t2); ip != std::end(t2); ++ip, ++it) {
101             assert ( it != c.end());
102         assert ( *ip == it->get());
103             }
104         assert ( it == c.end ());
105     }
106 #if __cplusplus >= 201103L
107     {
108         typedef int T;
109         typedef std::forward_list<T, min_allocator<T>> C;
110         const T t1[] = {0, 5, 5, 0, 0, 0, 5};
111         const T t2[] = {5, 5, 5};
112         C c1(std::begin(t1), std::end(t1));
113         C c2(std::begin(t2), std::end(t2));
114         c1.remove(0);
115         assert(c1 == c2);
116     }
117     {
118         typedef int T;
119         typedef std::forward_list<T, min_allocator<T>> C;
120         const T t1[] = {0, 0, 0, 0};
121         C c1(std::begin(t1), std::end(t1));
122         C c2;
123         c1.remove(0);
124         assert(c1 == c2);
125     }
126     {
127         typedef int T;
128         typedef std::forward_list<T, min_allocator<T>> C;
129         const T t1[] = {5, 5, 5};
130         const T t2[] = {5, 5, 5};
131         C c1(std::begin(t1), std::end(t1));
132         C c2(std::begin(t2), std::end(t2));
133         c1.remove(0);
134         assert(c1 == c2);
135     }
136     {
137         typedef int T;
138         typedef std::forward_list<T, min_allocator<T>> C;
139         C c1;
140         C c2;
141         c1.remove(0);
142         assert(c1 == c2);
143     }
144     {
145         typedef int T;
146         typedef std::forward_list<T, min_allocator<T>> C;
147         const T t1[] = {5, 5, 5, 0};
148         const T t2[] = {5, 5, 5};
149         C c1(std::begin(t1), std::end(t1));
150         C c2(std::begin(t2), std::end(t2));
151         c1.remove(0);
152         assert(c1 == c2);
153     }
154 #endif
155 }