1// Bob Walters 10-2008
2
3// Test for Container using non-standard pointer types.
4
5// Copyright (C) 2008-2015 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 3, 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 COPYING3.  If not see
20// <http://www.gnu.org/licenses/>.
21
22
23#include <vector>
24#include <testsuite_hooks.h>
25#include <ext/extptr_allocator.h>
26
27const int  A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
28const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
29const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15};
30const int A3[] = {0, 2, 3, 4, 10, 11};
31const int A4[] = {4, 10, 11};
32const int A5[] = {4, 10};
33const unsigned int  N = sizeof(A)  / sizeof(int);
34const unsigned int N1 = sizeof(A1) / sizeof(int);
35const unsigned int N2 = sizeof(A2) / sizeof(int);
36const unsigned int N3 = sizeof(A3) / sizeof(int);
37const unsigned int N4 = sizeof(A4) / sizeof(int);
38const unsigned int N5 = sizeof(A5) / sizeof(int);
39
40void
41test01()
42{
43  bool test __attribute__((unused)) = true;
44
45  typedef std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> >  vec_type;
46  typedef vec_type::iterator iterator_type;
47
48  vec_type v(A, A + N);
49
50  iterator_type it1 = v.erase(v.begin() + 1);
51  VERIFY( it1 == v.begin() + 1 );
52  VERIFY( v.size() == N1 );
53  VERIFY( std::equal(v.begin(), v.end(), A1) );
54
55  iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
56  VERIFY( it2 == v.begin() + 4 );
57  VERIFY( v.size() == N2 );
58  VERIFY( std::equal(v.begin(), v.end(), A2) );
59
60  iterator_type it3 = v.erase(v.begin() + 6, v.end());
61  VERIFY( it3 == v.begin() + 6 );
62  VERIFY( v.size() == N3 );
63  VERIFY( std::equal(v.begin(), v.end(), A3) );
64
65  iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
66  VERIFY( it4 == v.begin() );
67  VERIFY( v.size() == N4 );
68  VERIFY( std::equal(v.begin(), v.end(), A4) );
69
70  iterator_type it5 = v.erase(v.begin() + 2);
71  VERIFY( it5 == v.begin() + 2 );
72  VERIFY( v.size() == N5 );
73  VERIFY( std::equal(v.begin(), v.end(), A5) );
74
75  iterator_type it6 = v.erase(v.begin(), v.end());
76  VERIFY( it6 == v.begin() );
77  VERIFY( v.empty() );
78}
79
80void
81test02()
82{
83  bool test __attribute__((unused)) = true;
84
85  typedef __gnu_cxx::_ExtPtr_allocator<int> int_alloc_type;
86  typedef __gnu_cxx::_ExtPtr_allocator< std::vector<int, int_alloc_type> > vec_alloc_type;
87  typedef std::vector<std::vector<int, int_alloc_type >,vec_alloc_type>  vec_type;
88  typedef vec_type::iterator          iterator_type;
89
90  vec_type v, v1, v2, v3, v4, v5;
91  for (unsigned int i = 0; i < N; ++i)
92    v.push_back(std::vector<int,int_alloc_type>(1, A[i]));
93  for (unsigned int i = 0; i < N1; ++i)
94    v1.push_back(std::vector<int,int_alloc_type>(1, A1[i]));
95  for (unsigned int i = 0; i < N2; ++i)
96    v2.push_back(std::vector<int,int_alloc_type>(1, A2[i]));
97  for (unsigned int i = 0; i < N3; ++i)
98    v3.push_back(std::vector<int,int_alloc_type>(1, A3[i]));
99  for (unsigned int i = 0; i < N4; ++i)
100    v4.push_back(std::vector<int,int_alloc_type>(1, A4[i]));
101  for (unsigned int i = 0; i < N5; ++i)
102    v5.push_back(std::vector<int,int_alloc_type>(1, A5[i]));
103
104  iterator_type it1 = v.erase(v.begin() + 1);
105  VERIFY( it1 == v.begin() + 1 );
106  VERIFY( v.size() == N1 );
107  VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
108
109  iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
110  VERIFY( it2 == v.begin() + 4 );
111  VERIFY( v.size() == N2 );
112  VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
113
114  iterator_type it3 = v.erase(v.begin() + 6, v.end());
115  VERIFY( it3 == v.begin() + 6 );
116  VERIFY( v.size() == N3 );
117  VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
118
119  iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
120  VERIFY( it4 == v.begin() );
121  VERIFY( v.size() == N4 );
122  VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
123
124  iterator_type it5 = v.erase(v.begin() + 2);
125  VERIFY( it5 == v.begin() + 2 );
126  VERIFY( v.size() == N5 );
127  VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
128
129  iterator_type it6 = v.erase(v.begin(), v.end());
130  VERIFY( it6 == v.begin() );
131  VERIFY( v.empty() );
132}
133
134int main()
135{
136  test01();
137  test02();
138  return 0;
139}
140