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