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