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