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_front(value_type&& v); 14 15 #include <deque> 16 #include <cassert> 17 #include <cstddef> 18 19 #include "MoveOnly.h" 20 #include "min_allocator.h" 21 22 23 template <class C> 24 C 25 make(int size, int start = 0 ) 26 { 27 const int b = 4096 / sizeof(int); 28 int init = 0; 29 if (start > 0) 30 { 31 init = (start+1) / b + ((start+1) % b != 0); 32 init *= b; 33 --init; 34 } 35 C c(init); 36 for (int i = 0; i < init-start; ++i) 37 c.pop_back(); 38 for (int i = 0; i < size; ++i) 39 c.push_back(MoveOnly(i)); 40 for (int i = 0; i < start; ++i) 41 c.pop_front(); 42 return c; 43 } 44 45 template <class C> 46 void 47 test(C& c1, int x) 48 { 49 typedef typename C::iterator I; 50 std::size_t c1_osize = c1.size(); 51 c1.push_front(MoveOnly(x)); 52 assert(c1.size() == c1_osize + 1); 53 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size()); 54 I i = c1.begin(); 55 assert(*i == MoveOnly(x)); 56 ++i; 57 for (int j = 0; static_cast<std::size_t>(j) < c1_osize; ++j, ++i) 58 assert(*i == MoveOnly(j)); 59 } 60 61 template <class C> 62 void 63 testN(int start, int N) 64 { 65 C c1 = make<C>(N, start); 66 test(c1, -10); 67 } 68 69 70 int main(int, char**) 71 { 72 { 73 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 74 const int N = sizeof(rng)/sizeof(rng[0]); 75 for (int i = 0; i < N; ++i) 76 for (int j = 0; j < N; ++j) 77 testN<std::deque<MoveOnly> >(rng[i], rng[j]); 78 } 79 { 80 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 81 const int N = sizeof(rng)/sizeof(rng[0]); 82 for (int i = 0; i < N; ++i) 83 for (int j = 0; j < N; ++j) 84 testN<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[i], rng[j]); 85 } 86 87 return 0; 88 } 89