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 f, const_iterator l)
13 
14 #include <deque>
15 #include <cassert>
16 
17 #include "min_allocator.h"
18 
19 template <class C>
20 C
make(int size,int start=0)21 make(int size, int start = 0 )
22 {
23     const int b = 4096 / sizeof(int);
24     int init = 0;
25     if (start > 0)
26     {
27         init = (start+1) / b + ((start+1) % b != 0);
28         init *= b;
29         --init;
30     }
31     C c(init, 0);
32     for (int i = 0; i < init-start; ++i)
33         c.pop_back();
34     for (int i = 0; i < size; ++i)
35         c.push_back(i);
36     for (int i = 0; i < start; ++i)
37         c.pop_front();
38     return c;
39 };
40 
41 template <class C>
42 void
test(int P,C & c1,int size)43 test(int P, C& c1, int size)
44 {
45     typedef typename C::iterator I;
46     assert(P + size <= c1.size());
47     std::size_t c1_osize = c1.size();
48     I i = c1.erase(c1.cbegin() + P, c1.cbegin() + (P + size));
49     assert(i == c1.begin() + P);
50     assert(c1.size() == c1_osize - size);
51     assert(distance(c1.begin(), c1.end()) == c1.size());
52     i = c1.begin();
53     int j = 0;
54     for (; j < P; ++j, ++i)
55         assert(*i == j);
56     for (j += size; j < c1_osize; ++j, ++i)
57         assert(*i == j);
58 }
59 
60 template <class C>
61 void
testN(int start,int N)62 testN(int start, int N)
63 {
64     int pstep = std::max(N / std::max(std::min(N, 10), 1), 1);
65     for (int p = 0; p <= N; p += pstep)
66     {
67         int sstep = std::max((N - p) / std::max(std::min(N - p, 10), 1), 1);
68         for (int s = 0; s <= N - p; s += sstep)
69         {
70             C c1 = make<C>(N, start);
71             test(p, c1, s);
72         }
73     }
74 }
75 
main()76 int main()
77 {
78     {
79     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
80     const int N = sizeof(rng)/sizeof(rng[0]);
81     for (int i = 0; i < N; ++i)
82         for (int j = 0; j < N; ++j)
83             testN<std::deque<int> >(rng[i], rng[j]);
84     }
85 #if __cplusplus >= 201103L
86     {
87     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
88     const int N = sizeof(rng)/sizeof(rng[0]);
89     for (int i = 0; i < N; ++i)
90         for (int j = 0; j < N; ++j)
91             testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j]);
92     }
93 #endif
94 }
95