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 // template <class InputIterator> 13 // void assign(InputIterator f, InputIterator l); 14 15 #include <deque> 16 #include <cassert> 17 18 #include "test_iterators.h" 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(C& c1, const C& c2) 46 { 47 std::size_t c1_osize = c1.size(); 48 c1.assign(c2.begin(), c2.end()); 49 assert(distance(c1.begin(), c1.end()) == c1.size()); 50 assert(c1 == c2); 51 } 52 53 template <class C> 54 void 55 testN(int start, int N, int M) 56 { 57 typedef typename C::iterator I; 58 typedef typename C::const_iterator CI; 59 C c1 = make<C>(N, start); 60 C c2 = make<C>(M); 61 test(c1, c2); 62 } 63 64 template <class C> 65 void 66 testI(C& c1, const C& c2) 67 { 68 typedef typename C::const_iterator CI; 69 typedef input_iterator<CI> ICI; 70 std::size_t c1_osize = c1.size(); 71 c1.assign(ICI(c2.begin()), ICI(c2.end())); 72 assert(distance(c1.begin(), c1.end()) == c1.size()); 73 assert(c1 == c2); 74 } 75 76 template <class C> 77 void 78 testNI(int start, int N, int M) 79 { 80 typedef typename C::iterator I; 81 typedef typename C::const_iterator CI; 82 C c1 = make<C>(N, start); 83 C c2 = make<C>(M); 84 testI(c1, c2); 85 } 86 87 int main() 88 { 89 { 90 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 91 const int N = sizeof(rng)/sizeof(rng[0]); 92 for (int i = 0; i < N; ++i) 93 for (int j = 0; j < N; ++j) 94 for (int k = 0; k < N; ++k) 95 testN<std::deque<int> >(rng[i], rng[j], rng[k]); 96 testNI<std::deque<int> >(1500, 2000, 1000); 97 } 98 #if __cplusplus >= 201103L 99 { 100 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 101 const int N = sizeof(rng)/sizeof(rng[0]); 102 for (int i = 0; i < N; ++i) 103 for (int j = 0; j < N; ++j) 104 for (int k = 0; k < N; ++k) 105 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]); 106 testNI<std::deque<int, min_allocator<int>> >(1500, 2000, 1000); 107 } 108 #endif 109 } 110