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