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