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 // void shrink_to_fit(); 13 14 #include <deque> 15 #include <cassert> 16 17 std::deque<int> 18 make(int size, int start = 0 ) 19 { 20 const int b = 4096 / sizeof(int); 21 int init = 0; 22 if (start > 0) 23 { 24 init = (start+1) / b + ((start+1) % b != 0); 25 init *= b; 26 --init; 27 } 28 std::deque<int> c(init, 0); 29 for (int i = 0; i < init-start; ++i) 30 c.pop_back(); 31 for (int i = 0; i < size; ++i) 32 c.push_back(i); 33 for (int i = 0; i < start; ++i) 34 c.pop_front(); 35 return c; 36 }; 37 38 void 39 test(std::deque<int>& c1) 40 { 41 std::deque<int> s = c1; 42 c1.shrink_to_fit(); 43 assert(c1 == s); 44 } 45 46 void 47 testN(int start, int N) 48 { 49 typedef std::deque<int> C; 50 typedef C::const_iterator CI; 51 C c1 = make(N, start); 52 test(c1); 53 } 54 55 int main() 56 { 57 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 58 const int N = sizeof(rng)/sizeof(rng[0]); 59 for (int i = 0; i < N; ++i) 60 for (int j = 0; j < N; ++j) 61 testN(rng[i], rng[j]); 62 } 63