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