1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <deque>
11
12 // iterator erase(const_iterator p)
13
14 #include <deque>
15 #include <algorithm>
16 #include <iterator>
17 #include <cassert>
18 #include <cstddef>
19
20 #include "min_allocator.h"
21
22 template <class C>
23 C
make(int size,int start=0)24 make(int size, int start = 0 )
25 {
26 const int b = 4096 / sizeof(int);
27 int init = 0;
28 if (start > 0)
29 {
30 init = (start+1) / b + ((start+1) % b != 0);
31 init *= b;
32 --init;
33 }
34 C c(init, 0);
35 for (int i = 0; i < init-start; ++i)
36 c.pop_back();
37 for (int i = 0; i < size; ++i)
38 c.push_back(i);
39 for (int i = 0; i < start; ++i)
40 c.pop_front();
41 return c;
42 }
43
44 template <class C>
45 void
test(int P,C & c1)46 test(int P, C& c1)
47 {
48 typedef typename C::iterator I;
49 assert(static_cast<std::size_t>(P) < c1.size());
50 std::size_t c1_osize = c1.size();
51 I i = c1.erase(c1.cbegin() + P);
52 assert(i == c1.begin() + P);
53 assert(c1.size() == c1_osize - 1);
54 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
55 i = c1.begin();
56 int j = 0;
57 for (; j < P; ++j, ++i)
58 assert(*i == j);
59 for (++j; static_cast<std::size_t>(j) < c1_osize; ++j, ++i)
60 assert(*i == j);
61 }
62
63 template <class C>
64 void
testN(int start,int N)65 testN(int start, int N)
66 {
67 int pstep = std::max(N / std::max(std::min(N, 10), 1), 1);
68 for (int p = 0; p < N; p += pstep)
69 {
70 C c1 = make<C>(N, start);
71 test(p, c1);
72 }
73 }
74
main()75 int main()
76 {
77 {
78 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
79 const int N = sizeof(rng)/sizeof(rng[0]);
80 for (int i = 0; i < N; ++i)
81 for (int j = 0; j < N; ++j)
82 testN<std::deque<int> >(rng[i], rng[j]);
83 }
84 #if TEST_STD_VER >= 11
85 {
86 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
87 const int N = sizeof(rng)/sizeof(rng[0]);
88 for (int i = 0; i < N; ++i)
89 for (int j = 0; j < N; ++j)
90 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j]);
91 }
92 #endif
93 }
94