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 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
37     for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
38         assert(*i == T());
39 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
40     }
41     assert(DefaultOnly::count == 0);
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 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
58     for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
59         assert(*i == T());
60 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
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 #endif
78 }
79 
80 template <class T, class Allocator>
81 void
82 test(unsigned n)
83 {
84     test1<T, Allocator> ( n );
85     test2<T, Allocator> ( n );
86 }
87 
88 int main()
89 {
90     test<DefaultOnly, std::allocator<DefaultOnly> >(0);
91     test<DefaultOnly, std::allocator<DefaultOnly> >(1);
92     test<DefaultOnly, std::allocator<DefaultOnly> >(10);
93     test<DefaultOnly, std::allocator<DefaultOnly> >(1023);
94     test<DefaultOnly, std::allocator<DefaultOnly> >(1024);
95     test<DefaultOnly, std::allocator<DefaultOnly> >(1025);
96     test<DefaultOnly, std::allocator<DefaultOnly> >(2047);
97     test<DefaultOnly, std::allocator<DefaultOnly> >(2048);
98     test<DefaultOnly, std::allocator<DefaultOnly> >(2049);
99     test<DefaultOnly, std::allocator<DefaultOnly> >(4095);
100     test<DefaultOnly, std::allocator<DefaultOnly> >(4096);
101     test<DefaultOnly, std::allocator<DefaultOnly> >(4097);
102 
103     LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095));
104 
105 #if TEST_STD_VER >= 11
106     test<DefaultOnly, min_allocator<DefaultOnly> >(4095);
107 #endif
108 
109 #if TEST_STD_VER > 11
110     test3<DefaultOnly, std::allocator<DefaultOnly>> (1023);
111     test3<int, std::allocator<int>>(1);
112     test3<int, min_allocator<int>> (3);
113 #endif
114 
115 }
116