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 // Optimization for deque::iterators 13 14 // template <class InputIterator, class OutputIterator> 15 // OutputIterator 16 // move(InputIterator first, InputIterator last, OutputIterator result); 17 18 #include <deque> 19 #include <cassert> 20 21 #include "test_iterators.h" 22 23 std::deque<int> 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 std::deque<int> 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 44 void testN(int start, int N) 45 { 46 typedef std::deque<int> C; 47 typedef C::iterator I; 48 typedef C::const_iterator CI; 49 typedef random_access_iterator<I> RAI; 50 typedef random_access_iterator<CI> RACI; 51 C c1 = make(N, start); 52 C c2 = make(N); 53 assert(std::move(c1.cbegin(), c1.cend(), c2.begin()) == c2.end()); 54 assert(c1 == c2); 55 assert(std::move(c2.cbegin(), c2.cend(), c1.begin()) == c1.end()); 56 assert(c1 == c2); 57 assert(std::move(c1.cbegin(), c1.cend(), RAI(c2.begin())) == RAI(c2.end())); 58 assert(c1 == c2); 59 assert(std::move(c2.cbegin(), c2.cend(), RAI(c1.begin())) == RAI(c1.end())); 60 assert(c1 == c2); 61 assert(std::move(RACI(c1.cbegin()), RACI(c1.cend()), c2.begin()) == c2.end()); 62 assert(c1 == c2); 63 assert(std::move(RACI(c2.cbegin()), RACI(c2.cend()), c1.begin()) == c1.end()); 64 assert(c1 == c2); 65 } 66 67 int main() 68 { 69 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 70 const int N = sizeof(rng)/sizeof(rng[0]); 71 for (int i = 0; i < N; ++i) 72 for (int j = 0; j < N; ++j) 73 testN(rng[i], rng[j]); 74 } 75