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 // UNSUPPORTED: c++98, c++03 10 11 // <deque> 12 13 // void push_back(value_type&& v); 14 // void pop_back(); 15 // void pop_front(); 16 17 #include <deque> 18 #include <cassert> 19 20 #include "MoveOnly.h" 21 #include "min_allocator.h" 22 23 24 template <class C> 25 C 26 make(int size, int start = 0 ) 27 { 28 const int b = 4096 / sizeof(int); 29 int init = 0; 30 if (start > 0) 31 { 32 init = (start+1) / b + ((start+1) % b != 0); 33 init *= b; 34 --init; 35 } 36 C c(init); 37 for (int i = 0; i < init-start; ++i) 38 c.pop_back(); 39 for (int i = 0; i < size; ++i) 40 c.push_back(MoveOnly(i)); 41 for (int i = 0; i < start; ++i) 42 c.pop_front(); 43 return c; 44 } 45 46 template <class C> 47 void test(int size) 48 { 49 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049}; 50 const int N = sizeof(rng)/sizeof(rng[0]); 51 for (int j = 0; j < N; ++j) 52 { 53 C c = make<C>(size, rng[j]); 54 typename C::const_iterator it = c.begin(); 55 for (int i = 0; i < size; ++i, ++it) 56 assert(*it == MoveOnly(i)); 57 } 58 } 59 60 61 int main(int, char**) 62 { 63 { 64 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; 65 const int N = sizeof(rng)/sizeof(rng[0]); 66 for (int j = 0; j < N; ++j) 67 test<std::deque<MoveOnly> >(rng[j]); 68 } 69 { 70 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; 71 const int N = sizeof(rng)/sizeof(rng[0]); 72 for (int j = 0; j < N; ++j) 73 test<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[j]); 74 } 75 76 return 0; 77 } 78