OSDN Git Service

2008-11-11 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / vector / ext_pointer / modifiers / erase.cc
1 // Bob Walters 10-2008
2
3 // Test for Container using non-standard pointer types.
4
5 // Copyright (C) 2008 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library.  This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING.  If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // USA.
22
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction.  Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License.  This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
31
32 #include <vector>
33 #include <testsuite_hooks.h>
34 #include <ext/extptr_allocator.h>
35
36 const int  A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
37 const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
38 const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15};
39 const int A3[] = {0, 2, 3, 4, 10, 11};
40 const int A4[] = {4, 10, 11};
41 const int A5[] = {4, 10};
42 const unsigned int  N = sizeof(A)  / sizeof(int);
43 const unsigned int N1 = sizeof(A1) / sizeof(int);
44 const unsigned int N2 = sizeof(A2) / sizeof(int);
45 const unsigned int N3 = sizeof(A3) / sizeof(int);
46 const unsigned int N4 = sizeof(A4) / sizeof(int);
47 const unsigned int N5 = sizeof(A5) / sizeof(int);
48
49 void
50 test01()
51 {
52   bool test __attribute__((unused)) = true;
53
54   typedef std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> >  vec_type;
55   typedef vec_type::iterator iterator_type;
56
57   vec_type v(A, A + N);
58
59   iterator_type it1 = v.erase(v.begin() + 1);
60   VERIFY( it1 == v.begin() + 1 );
61   VERIFY( v.size() == N1 );
62   VERIFY( std::equal(v.begin(), v.end(), A1) );
63   
64   iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
65   VERIFY( it2 == v.begin() + 4 );
66   VERIFY( v.size() == N2 );
67   VERIFY( std::equal(v.begin(), v.end(), A2) );
68   
69   iterator_type it3 = v.erase(v.begin() + 6, v.end());
70   VERIFY( it3 == v.begin() + 6 );
71   VERIFY( v.size() == N3 );
72   VERIFY( std::equal(v.begin(), v.end(), A3) );
73
74   iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
75   VERIFY( it4 == v.begin() );
76   VERIFY( v.size() == N4 );
77   VERIFY( std::equal(v.begin(), v.end(), A4) );
78
79   iterator_type it5 = v.erase(v.begin() + 2);
80   VERIFY( it5 == v.begin() + 2 );
81   VERIFY( v.size() == N5 );
82   VERIFY( std::equal(v.begin(), v.end(), A5) );
83
84   iterator_type it6 = v.erase(v.begin(), v.end());
85   VERIFY( it6 == v.begin() );
86   VERIFY( v.empty() );
87 }
88
89 void
90 test02()
91 {
92   bool test __attribute__((unused)) = true;
93
94   typedef __gnu_cxx::_ExtPtr_allocator<int> int_alloc_type;
95   typedef __gnu_cxx::_ExtPtr_allocator< std::vector<int, int_alloc_type> > vec_alloc_type;
96   typedef std::vector<std::vector<int, int_alloc_type >,vec_alloc_type>  vec_type; 
97   typedef vec_type::iterator          iterator_type;
98
99   vec_type v, v1, v2, v3, v4, v5;
100   for (unsigned int i = 0; i < N; ++i)
101     v.push_back(std::vector<int,int_alloc_type>(1, A[i]));
102   for (unsigned int i = 0; i < N1; ++i)
103     v1.push_back(std::vector<int,int_alloc_type>(1, A1[i]));
104   for (unsigned int i = 0; i < N2; ++i)
105     v2.push_back(std::vector<int,int_alloc_type>(1, A2[i]));
106   for (unsigned int i = 0; i < N3; ++i)
107     v3.push_back(std::vector<int,int_alloc_type>(1, A3[i]));
108   for (unsigned int i = 0; i < N4; ++i)
109     v4.push_back(std::vector<int,int_alloc_type>(1, A4[i]));
110   for (unsigned int i = 0; i < N5; ++i)
111     v5.push_back(std::vector<int,int_alloc_type>(1, A5[i]));
112   
113   iterator_type it1 = v.erase(v.begin() + 1);
114   VERIFY( it1 == v.begin() + 1 );
115   VERIFY( v.size() == N1 );
116   VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
117   
118   iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
119   VERIFY( it2 == v.begin() + 4 );
120   VERIFY( v.size() == N2 );
121   VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
122   
123   iterator_type it3 = v.erase(v.begin() + 6, v.end());
124   VERIFY( it3 == v.begin() + 6 );
125   VERIFY( v.size() == N3 );
126   VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
127
128   iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
129   VERIFY( it4 == v.begin() );
130   VERIFY( v.size() == N4 );
131   VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
132
133   iterator_type it5 = v.erase(v.begin() + 2);
134   VERIFY( it5 == v.begin() + 2 );
135   VERIFY( v.size() == N5 );
136   VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
137
138   iterator_type it6 = v.erase(v.begin(), v.end());
139   VERIFY( it6 == v.begin() );
140   VERIFY( v.empty() );
141 }
142
143 int main()
144 {
145   test01();
146   test02();
147   return 0;
148 }