1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant//                     The LLVM Compiler Infrastructure
4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details.
7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// <deque>
11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
12bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// explicit deque(size_type n);
13bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
14bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <deque>
15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <cassert>
16bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
17bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "../../../stack_allocator.h"
18e27dbcf2dce3505a2c6f2d385216ea4e76655df3Marshall Clow#include "DefaultOnly.h"
19061d0cc4db18d17bf01ed14c5db0be098205bd47Marshall Clow#include "min_allocator.h"
20bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
21bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnanttemplate <class T, class Allocator>
22bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantvoid
23ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowtest2(unsigned n)
24ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow{
25ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#if _LIBCPP_STD_VER > 11
26ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    typedef std::deque<T, Allocator> C;
27ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    typedef typename C::const_iterator const_iterator;
28ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    assert(DefaultOnly::count == 0);
29ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    {
30ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    C d(n, Allocator());
31ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    assert(DefaultOnly::count == n);
32ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    assert(d.size() == n);
33ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    assert(distance(d.begin(), d.end()) == d.size());
34ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
35ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
36ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow        assert(*i == T());
37ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
38ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    }
39ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    assert(DefaultOnly::count == 0);
40ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#endif
41ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow}
42ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow
43ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowtemplate <class T, class Allocator>
44ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowvoid
45ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowtest1(unsigned n)
46bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
47bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    typedef std::deque<T, Allocator> C;
48bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    typedef typename C::const_iterator const_iterator;
49bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(DefaultOnly::count == 0);
50bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    {
51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    C d(n);
52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(DefaultOnly::count == n);
53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(d.size() == n);
54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(distance(d.begin(), d.end()) == d.size());
5573d21a4f0774d3fadab98e690619a359cfb160a3Howard Hinnant#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
57bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(*i == T());
5873d21a4f0774d3fadab98e690619a359cfb160a3Howard Hinnant#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
59bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    }
60bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(DefaultOnly::count == 0);
61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
62bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
63ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowtemplate <class T, class Allocator>
64ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowvoid
65ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowtest3(unsigned n, Allocator const &alloc = Allocator())
66ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow{
67ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#if _LIBCPP_STD_VER > 11
68ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    typedef std::deque<T, Allocator> C;
69ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    typedef typename C::const_iterator const_iterator;
70ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    {
71ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    C d(n, alloc);
72ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    assert(d.size() == n);
73ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    assert(d.get_allocator() == alloc);
74ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    }
75ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#endif
76ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow}
77ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow
78ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowtemplate <class T, class Allocator>
79ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowvoid
80ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clowtest(unsigned n)
81ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow{
82ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    test1<T, Allocator> ( n );
83ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    test2<T, Allocator> ( n );
84ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow}
85ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow
86bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main()
87bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
88bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(0);
89bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(1);
90bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(10);
91bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(1023);
92bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(1024);
93bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(1025);
94bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(2047);
95bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(2048);
96bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(2049);
97bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(4095);
98bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(4096);
99bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<DefaultOnly, std::allocator<DefaultOnly> >(4097);
100ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow
101ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    test1<DefaultOnly, stack_allocator<DefaultOnly, 4096> >(4095);
102ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow
103fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant#if __cplusplus >= 201103L
104fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    test<DefaultOnly, min_allocator<DefaultOnly> >(4095);
105fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant#endif
106ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow
107ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#if _LIBCPP_STD_VER > 11
108ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    test3<DefaultOnly, std::allocator<DefaultOnly>> (1023);
109ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    test3<int, std::allocator<int>>(1);
110ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow    test3<int, min_allocator<int>> (3);
111ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow#endif
112ab04aadaf4e8ef81a2ebea176689c40333cb015eMarshall Clow
113bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
114