aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc
blob: 93ced1b906451fe03d6d8a7b31199af287c1e16b (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 2005-11-25  Paolo Carlini  <pcarlini@suse.de>

// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// 23.2.1.3 deque modifiers

#include <deque>
#include <testsuite_hooks.h>

const int  A[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
		  13, 14, 15};
const int A0[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const int A1[] = {-5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const int A2[] = {-5, 0, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15};
const int A3[] = {-5, 0, 1, 2, 8, 9, 10, 11};
const int A4[] = {2, 8, 9, 10, 11};
const int A5[] = {2, 8, 10, 11};
const int A6[] = {2, 8, 10};
const unsigned  N = sizeof(A)  / sizeof(int);
const unsigned N0 = sizeof(A0) / sizeof(int);
const unsigned N1 = sizeof(A1) / sizeof(int);
const unsigned N2 = sizeof(A2) / sizeof(int);
const unsigned N3 = sizeof(A3) / sizeof(int);
const unsigned N4 = sizeof(A4) / sizeof(int);
const unsigned N5 = sizeof(A5) / sizeof(int);
const unsigned N6 = sizeof(A6) / sizeof(int);

template<int Size>
  class My_class
  {
    double dummy[Size];
    int data;
    
  public:
    My_class(int num)
    : data(num) { }
    
    operator int() const
    { return data; }
  };

template<typename T>
  void
  test01()
  {
    bool test __attribute__((unused)) = true;
    
    typedef std::deque<T>                         deque_type;
    typedef typename deque_type::iterator      iterator_type;

    deque_type v(A, A + N);

    iterator_type it0 = v.erase(v.begin() + 1, v.begin() + 4);
    VERIFY( it0 == v.begin() + 1 );
    VERIFY( v.size() == N0 );
    VERIFY( std::equal(v.begin(), v.end(), A0) );
    
    iterator_type it1 = v.erase(v.begin() + 1);
    VERIFY( it1 == v.begin() + 1 );
    VERIFY( v.size() == N1 );
    VERIFY( std::equal(v.begin(), v.end(), A1) );
    
    iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
    VERIFY( it2 == v.begin() + 4 );
    VERIFY( v.size() == N2 );
    VERIFY( std::equal(v.begin(), v.end(), A2) );
  
    iterator_type it3 = v.erase(v.begin() + 8, v.end());
    VERIFY( it3 == v.begin() + 8 );
    VERIFY( v.size() == N3 );
    VERIFY( std::equal(v.begin(), v.end(), A3) );

    iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
    VERIFY( it4 == v.begin() );
    VERIFY( v.size() == N4 );
    VERIFY( std::equal(v.begin(), v.end(), A4) );
    
    iterator_type it5 = v.erase(v.begin() + 2);
    VERIFY( it5 == v.begin() + 2 );
    VERIFY( v.size() == N5 );
    VERIFY( std::equal(v.begin(), v.end(), A5) );

    iterator_type it6 = v.erase(v.begin() + 3, v.end());
    VERIFY( it6 == v.begin() + 3 );
    VERIFY( v.size() == N6 );
    VERIFY( std::equal(v.begin(), v.end(), A6) );

    iterator_type it7 = v.erase(v.begin(), v.end());
    VERIFY( it7 == v.begin() );
    VERIFY( v.empty() );
  }

int main()
{
  test01<My_class<1> >();
  test01<My_class<8> >();
  test01<My_class<32> >();
  return 0;
}