3 // Test for Container using non-standard pointer types.
5 // Copyright (C) 2008 Free Software Foundation, Inc.
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)
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.
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,
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.
33 #include <testsuite_hooks.h>
34 #include <ext/extptr_allocator.h>
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);
52 bool test __attribute__((unused)) = true;
54 typedef std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> > vec_type;
55 typedef vec_type::iterator iterator_type;
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) );
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) );
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) );
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) );
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) );
84 iterator_type it6 = v.erase(v.begin(), v.end());
85 VERIFY( it6 == v.begin() );
92 bool test __attribute__((unused)) = true;
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;
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]));
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()) );
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()) );
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()) );
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()) );
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()) );
138 iterator_type it6 = v.erase(v.begin(), v.end());
139 VERIFY( it6 == v.begin() );