]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / deque / modifiers / erase / 2.cc
CommitLineData
d2cc7f92
PC
1// 2005-11-25 Paolo Carlini <pcarlini@suse.de>
2
a945c346 3// Copyright (C) 2005-2024 Free Software Foundation, Inc.
d2cc7f92
PC
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
d2cc7f92
PC
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
d2cc7f92
PC
19
20// 23.2.1.3 deque modifiers
21
22#include <deque>
23#include <testsuite_hooks.h>
24
25const int A[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
26 13, 14, 15};
27const int A0[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
28const int A1[] = {-5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
29const int A2[] = {-5, 0, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15};
30const int A3[] = {-5, 0, 1, 2, 8, 9, 10, 11};
31const int A4[] = {2, 8, 9, 10, 11};
32const int A5[] = {2, 8, 10, 11};
33const int A6[] = {2, 8, 10};
7919bb2f
PC
34const unsigned N = sizeof(A) / sizeof(int);
35const unsigned N0 = sizeof(A0) / sizeof(int);
36const unsigned N1 = sizeof(A1) / sizeof(int);
37const unsigned N2 = sizeof(A2) / sizeof(int);
38const unsigned N3 = sizeof(A3) / sizeof(int);
39const unsigned N4 = sizeof(A4) / sizeof(int);
40const unsigned N5 = sizeof(A5) / sizeof(int);
41const unsigned N6 = sizeof(A6) / sizeof(int);
d2cc7f92
PC
42
43template<int Size>
44 class My_class
45 {
46 double dummy[Size];
47 int data;
48
49 public:
50 My_class(int num)
51 : data(num) { }
52
53 operator int() const
54 { return data; }
55 };
56
57template<typename T>
58 void
59 test01()
60 {
d2cc7f92
PC
61 typedef std::deque<T> deque_type;
62 typedef typename deque_type::iterator iterator_type;
63
64 deque_type v(A, A + N);
65
66 iterator_type it0 = v.erase(v.begin() + 1, v.begin() + 4);
67 VERIFY( it0 == v.begin() + 1 );
68 VERIFY( v.size() == N0 );
69 VERIFY( std::equal(v.begin(), v.end(), A0) );
70
71 iterator_type it1 = v.erase(v.begin() + 1);
72 VERIFY( it1 == v.begin() + 1 );
73 VERIFY( v.size() == N1 );
74 VERIFY( std::equal(v.begin(), v.end(), A1) );
75
76 iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
77 VERIFY( it2 == v.begin() + 4 );
78 VERIFY( v.size() == N2 );
79 VERIFY( std::equal(v.begin(), v.end(), A2) );
80
81 iterator_type it3 = v.erase(v.begin() + 8, v.end());
82 VERIFY( it3 == v.begin() + 8 );
83 VERIFY( v.size() == N3 );
84 VERIFY( std::equal(v.begin(), v.end(), A3) );
85
86 iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
87 VERIFY( it4 == v.begin() );
88 VERIFY( v.size() == N4 );
89 VERIFY( std::equal(v.begin(), v.end(), A4) );
90
91 iterator_type it5 = v.erase(v.begin() + 2);
92 VERIFY( it5 == v.begin() + 2 );
93 VERIFY( v.size() == N5 );
94 VERIFY( std::equal(v.begin(), v.end(), A5) );
95
96 iterator_type it6 = v.erase(v.begin() + 3, v.end());
97 VERIFY( it6 == v.begin() + 3 );
98 VERIFY( v.size() == N6 );
99 VERIFY( std::equal(v.begin(), v.end(), A6) );
100
101 iterator_type it7 = v.erase(v.begin(), v.end());
102 VERIFY( it7 == v.begin() );
103 VERIFY( v.empty() );
104 }
105
106int main()
107{
108 test01<My_class<1> >();
109 test01<My_class<8> >();
110 test01<My_class<32> >();
111 return 0;
112}