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 { 72 C d(n, alloc); 73 assert(d.size() == n); 74 assert(d.get_allocator() == alloc); 75 } 76 #else 77 ((void)n); 78 ((void)alloc); 79 #endif 80 } 81 82 template <class T, class Allocator> 83 void 84 test(unsigned n) 85 { 86 test1<T, Allocator> ( n ); 87 test2<T, Allocator> ( n ); 88 } 89 90 int main() 91 { 92 test<DefaultOnly, std::allocator<DefaultOnly> >(0); 93 test<DefaultOnly, std::allocator<DefaultOnly> >(1); 94 test<DefaultOnly, std::allocator<DefaultOnly> >(10); 95 test<DefaultOnly, std::allocator<DefaultOnly> >(1023); 96 test<DefaultOnly, std::allocator<DefaultOnly> >(1024); 97 test<DefaultOnly, std::allocator<DefaultOnly> >(1025); 98 test<DefaultOnly, std::allocator<DefaultOnly> >(2047); 99 test<DefaultOnly, std::allocator<DefaultOnly> >(2048); 100 test<DefaultOnly, std::allocator<DefaultOnly> >(2049); 101 test<DefaultOnly, std::allocator<DefaultOnly> >(4095); 102 test<DefaultOnly, std::allocator<DefaultOnly> >(4096); 103 test<DefaultOnly, std::allocator<DefaultOnly> >(4097); 104 105 LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095)); 106 107 #if TEST_STD_VER >= 11 108 test<DefaultOnly, min_allocator<DefaultOnly> >(4095); 109 #endif 110 111 #if TEST_STD_VER > 11 112 test3<DefaultOnly, std::allocator<DefaultOnly>> (1023); 113 test3<int, std::allocator<int>>(1); 114 test3<int, min_allocator<int>> (3); 115 #endif 116 117 } 118