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