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 // explicit deque(size_type n); 12 13 #include <deque> 14 #include <cassert> 15 #include <cstddef> 16 17 #include "test_macros.h" 18 #include "test_allocator.h" 19 #include "DefaultOnly.h" 20 #include "min_allocator.h" 21 22 template <class T, class Allocator> 23 void 24 test2(unsigned n) 25 { 26 #if TEST_STD_VER > 11 27 typedef std::deque<T, Allocator> C; 28 typedef typename C::const_iterator const_iterator; 29 assert(DefaultOnly::count == 0); 30 { 31 C d(n, Allocator()); 32 assert(static_cast<unsigned>(DefaultOnly::count) == n); 33 assert(d.size() == n); 34 assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size()); 35 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) 36 assert(*i == T()); 37 } 38 assert(DefaultOnly::count == 0); 39 #else 40 ((void)n); 41 #endif 42 } 43 44 template <class T, class Allocator> 45 void 46 test1(unsigned n) 47 { 48 typedef std::deque<T, Allocator> C; 49 typedef typename C::const_iterator const_iterator; 50 assert(DefaultOnly::count == 0); 51 { 52 C d(n); 53 assert(static_cast<unsigned>(DefaultOnly::count) == n); 54 assert(d.size() == n); 55 assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size()); 56 #if TEST_STD_VER >= 11 57 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) 58 assert(*i == T()); 59 #endif 60 } 61 assert(DefaultOnly::count == 0); 62 } 63 64 template <class T, class Allocator> 65 void 66 test3(unsigned n, Allocator const &alloc = Allocator()) 67 { 68 #if TEST_STD_VER > 11 69 typedef std::deque<T, Allocator> C; 70 { 71 C d(n, alloc); 72 assert(d.size() == n); 73 assert(d.get_allocator() == alloc); 74 } 75 #else 76 ((void)n); 77 ((void)alloc); 78 #endif 79 } 80 81 template <class T, class Allocator> 82 void 83 test(unsigned n) 84 { 85 test1<T, Allocator> ( n ); 86 test2<T, Allocator> ( n ); 87 } 88 89 int main(int, char**) 90 { 91 test<DefaultOnly, std::allocator<DefaultOnly> >(0); 92 test<DefaultOnly, std::allocator<DefaultOnly> >(1); 93 test<DefaultOnly, std::allocator<DefaultOnly> >(10); 94 test<DefaultOnly, std::allocator<DefaultOnly> >(1023); 95 test<DefaultOnly, std::allocator<DefaultOnly> >(1024); 96 test<DefaultOnly, std::allocator<DefaultOnly> >(1025); 97 test<DefaultOnly, std::allocator<DefaultOnly> >(2047); 98 test<DefaultOnly, std::allocator<DefaultOnly> >(2048); 99 test<DefaultOnly, std::allocator<DefaultOnly> >(2049); 100 test<DefaultOnly, std::allocator<DefaultOnly> >(4095); 101 test<DefaultOnly, std::allocator<DefaultOnly> >(4096); 102 test<DefaultOnly, std::allocator<DefaultOnly> >(4097); 103 104 LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095)); 105 106 #if TEST_STD_VER >= 11 107 test<DefaultOnly, min_allocator<DefaultOnly> >(4095); 108 #endif 109 110 #if TEST_STD_VER > 11 111 test3<DefaultOnly, std::allocator<DefaultOnly>> (1023); 112 test3<int, std::allocator<int>>(1); 113 test3<int, min_allocator<int>> (3); 114 #endif 115 116 117 return 0; 118 } 119