summaryrefslogtreecommitdiffstats
path: root/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp
blob: 106c0527f5f47f9931c2a2762e7219ff9a654cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <list>

// void remove(const value_type& value);

#include <list>
#include <cassert>

#include "min_allocator.h"

struct S {
	S(int i) : i_(new int(i)) {}
	S(const S &rhs) : i_(new int(*rhs.i_)) {}
	S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; }
	~S () { delete i_; i_ = NULL; }
	bool operator == (const S &rhs) const { return *i_ == *rhs.i_; }
	int get () const { return *i_; }
	int *i_;
	};


int main()
{
    {
    int a1[] = {1, 2, 3, 4};
    int a2[] = {1, 2, 4};
    std::list<int> c(a1, a1+4);
    c.remove(3);
    assert(c == std::list<int>(a2, a2+3));
    }
    {  // LWG issue #526
    int a1[] = {1, 2, 1, 3, 5, 8, 11};
    int a2[] = {   2,    3, 5, 8, 11};
    std::list<int> c(a1, a1+7);
    c.remove(c.front());
    assert(c == std::list<int>(a2, a2+5));
    }
    {
    int a1[] = {1, 2, 1, 3, 5, 8, 11, 1};
    int a2[] = {   2,    3, 5, 8, 11   };
    std::list<S> c;
    for(int *ip = a1; ip < a1+8; ++ip)
        c.push_back(S(*ip));
    c.remove(c.front());
    std::list<S>::const_iterator it = c.begin();
    for(int *ip = a2; ip < a2+5; ++ip, ++it) {
	    assert ( it != c.end());
        assert ( *ip == it->get());
	    }
	assert ( it == c.end ());
    }
#if __cplusplus >= 201103L
    {
    int a1[] = {1, 2, 3, 4};
    int a2[] = {1, 2, 4};
    std::list<int, min_allocator<int>> c(a1, a1+4);
    c.remove(3);
    assert((c == std::list<int, min_allocator<int>>(a2, a2+3)));
    }
#endif
}
OpenPOWER on IntegriCloud