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 #include <deque> 15 #include <cassert> 16 17 #include "../../../MoveOnly.h" 18 #include "min_allocator.h" 19 20 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 21 22 template <class C> 23 C 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); 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(MoveOnly(i)); 39 for (int i = 0; i < start; ++i) 40 c.pop_front(); 41 return c; 42 }; 43 44 template <class C> 45 void 46 test(int P, C& c1, int x) 47 { 48 typedef typename C::iterator I; 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 typedef typename C::iterator I; 69 typedef typename C::const_iterator CI; 70 for (int i = 0; i <= 3; ++i) 71 { 72 if (0 <= i && i <= N) 73 { 74 C c1 = make<C>(N, start); 75 test(i, c1, -10); 76 } 77 } 78 for (int i = N/2-1; i <= N/2+1; ++i) 79 { 80 if (0 <= i && i <= N) 81 { 82 C c1 = make<C>(N, start); 83 test(i, c1, -10); 84 } 85 } 86 for (int i = N - 3; i <= N; ++i) 87 { 88 if (0 <= i && i <= N) 89 { 90 C c1 = make<C>(N, start); 91 test(i, c1, -10); 92 } 93 } 94 } 95 96 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 97 98 int main() 99 { 100 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 101 { 102 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 103 const int N = sizeof(rng)/sizeof(rng[0]); 104 for (int i = 0; i < N; ++i) 105 for (int j = 0; j < N; ++j) 106 testN<std::deque<MoveOnly> >(rng[i], rng[j]); 107 } 108 #if __cplusplus >= 201103L 109 { 110 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 111 const int N = sizeof(rng)/sizeof(rng[0]); 112 for (int i = 0; i < N; ++i) 113 for (int j = 0; j < N; ++j) 114 testN<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[i], rng[j]); 115 } 116 #endif 117 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 118 } 119