]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / deque / modifiers / erase / 2.cc
1 // 2005-11-25 Paolo Carlini <pcarlini@suse.de>
2
3 // Copyright (C) 2005-2014 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 23.2.1.3 deque modifiers
21
22 #include <deque>
23 #include <testsuite_hooks.h>
24
25 const int A[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
26 13, 14, 15};
27 const int A0[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
28 const int A1[] = {-5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
29 const int A2[] = {-5, 0, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15};
30 const int A3[] = {-5, 0, 1, 2, 8, 9, 10, 11};
31 const int A4[] = {2, 8, 9, 10, 11};
32 const int A5[] = {2, 8, 10, 11};
33 const int A6[] = {2, 8, 10};
34 const unsigned N = sizeof(A) / sizeof(int);
35 const unsigned N0 = sizeof(A0) / sizeof(int);
36 const unsigned N1 = sizeof(A1) / sizeof(int);
37 const unsigned N2 = sizeof(A2) / sizeof(int);
38 const unsigned N3 = sizeof(A3) / sizeof(int);
39 const unsigned N4 = sizeof(A4) / sizeof(int);
40 const unsigned N5 = sizeof(A5) / sizeof(int);
41 const unsigned N6 = sizeof(A6) / sizeof(int);
42
43 template<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
57 template<typename T>
58 void
59 test01()
60 {
61 bool test __attribute__((unused)) = true;
62
63 typedef std::deque<T> deque_type;
64 typedef typename deque_type::iterator iterator_type;
65
66 deque_type v(A, A + N);
67
68 iterator_type it0 = v.erase(v.begin() + 1, v.begin() + 4);
69 VERIFY( it0 == v.begin() + 1 );
70 VERIFY( v.size() == N0 );
71 VERIFY( std::equal(v.begin(), v.end(), A0) );
72
73 iterator_type it1 = v.erase(v.begin() + 1);
74 VERIFY( it1 == v.begin() + 1 );
75 VERIFY( v.size() == N1 );
76 VERIFY( std::equal(v.begin(), v.end(), A1) );
77
78 iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
79 VERIFY( it2 == v.begin() + 4 );
80 VERIFY( v.size() == N2 );
81 VERIFY( std::equal(v.begin(), v.end(), A2) );
82
83 iterator_type it3 = v.erase(v.begin() + 8, v.end());
84 VERIFY( it3 == v.begin() + 8 );
85 VERIFY( v.size() == N3 );
86 VERIFY( std::equal(v.begin(), v.end(), A3) );
87
88 iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
89 VERIFY( it4 == v.begin() );
90 VERIFY( v.size() == N4 );
91 VERIFY( std::equal(v.begin(), v.end(), A4) );
92
93 iterator_type it5 = v.erase(v.begin() + 2);
94 VERIFY( it5 == v.begin() + 2 );
95 VERIFY( v.size() == N5 );
96 VERIFY( std::equal(v.begin(), v.end(), A5) );
97
98 iterator_type it6 = v.erase(v.begin() + 3, v.end());
99 VERIFY( it6 == v.begin() + 3 );
100 VERIFY( v.size() == N6 );
101 VERIFY( std::equal(v.begin(), v.end(), A6) );
102
103 iterator_type it7 = v.erase(v.begin(), v.end());
104 VERIFY( it7 == v.begin() );
105 VERIFY( v.empty() );
106 }
107
108 int main()
109 {
110 test01<My_class<1> >();
111 test01<My_class<8> >();
112 test01<My_class<32> >();
113 return 0;
114 }