1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <deque> 10 11 // void push_back(const value_type& v); 12 // void pop_back(); 13 // void pop_front(); 14 15 #include <deque> 16 #include <cassert> 17 18 #include "min_allocator.h" 19 20 template <class C> 21 C 22 make(int size, int start = 0 ) 23 { 24 const int b = 4096 / sizeof(int); 25 int init = 0; 26 if (start > 0) 27 { 28 init = (start+1) / b + ((start+1) % b != 0); 29 init *= b; 30 --init; 31 } 32 C c(init, 0); 33 for (int i = 0; i < init-start; ++i) 34 c.pop_back(); 35 for (int i = 0; i < size; ++i) 36 c.push_back(i); 37 for (int i = 0; i < start; ++i) 38 c.pop_front(); 39 return c; 40 } 41 42 template <class C> 43 void test(int size) 44 { 45 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049}; 46 const int N = sizeof(rng)/sizeof(rng[0]); 47 for (int j = 0; j < N; ++j) 48 { 49 C c = make<C>(size, rng[j]); 50 typename C::const_iterator it = c.begin(); 51 for (int i = 0; i < size; ++i, ++it) 52 assert(*it == i); 53 } 54 } 55 56 int main(int, char**) 57 { 58 { 59 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; 60 const int N = sizeof(rng)/sizeof(rng[0]); 61 for (int j = 0; j < N; ++j) 62 test<std::deque<int> >(rng[j]); 63 } 64 #if TEST_STD_VER >= 11 65 { 66 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; 67 const int N = sizeof(rng)/sizeof(rng[0]); 68 for (int j = 0; j < N; ++j) 69 test<std::deque<int, min_allocator<int>> >(rng[j]); 70 } 71 #endif 72 73 return 0; 74 } 75