[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.cons / size.pass.cpp
blobb69d2bb598ed56c107964065355e0925d9b2b0ce
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <deque>
11 // explicit deque(size_type n);
13 #include <deque>
14 #include <cassert>
15 #include <cstddef>
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "DefaultOnly.h"
20 #include "min_allocator.h"
22 template <class T, class Allocator>
23 void
24 test2(unsigned n)
26 #if TEST_STD_VER > 11
27 typedef std::deque<T, Allocator> C;
28 typedef typename C::const_iterator const_iterator;
29 assert(DefaultOnly::count == 0);
31 C d(n, Allocator());
32 assert(static_cast<unsigned>(DefaultOnly::count) == n);
33 assert(d.size() == n);
34 assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
35 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
36 assert(*i == T());
38 assert(DefaultOnly::count == 0);
39 #else
40 ((void)n);
41 #endif
44 template <class T, class Allocator>
45 void
46 test1(unsigned n)
48 typedef std::deque<T, Allocator> C;
49 typedef typename C::const_iterator const_iterator;
50 assert(DefaultOnly::count == 0);
52 C d(n);
53 assert(static_cast<unsigned>(DefaultOnly::count) == n);
54 assert(d.size() == n);
55 assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
56 #if TEST_STD_VER >= 11
57 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
58 assert(*i == T());
59 #endif
61 assert(DefaultOnly::count == 0);
64 template <class T, class Allocator>
65 void
66 test3(unsigned n, Allocator const &alloc = Allocator())
68 #if TEST_STD_VER > 11
69 typedef std::deque<T, Allocator> C;
71 C d(n, alloc);
72 assert(d.size() == n);
73 assert(d.get_allocator() == alloc);
75 #else
76 ((void)n);
77 ((void)alloc);
78 #endif
81 template <class T, class Allocator>
82 void
83 test(unsigned n)
85 test1<T, Allocator> ( n );
86 test2<T, Allocator> ( n );
89 int main(int, char**)
91 test<DefaultOnly, std::allocator<DefaultOnly> >(0);
92 test<DefaultOnly, std::allocator<DefaultOnly> >(1);
93 test<DefaultOnly, std::allocator<DefaultOnly> >(10);
94 test<DefaultOnly, std::allocator<DefaultOnly> >(1023);
95 test<DefaultOnly, std::allocator<DefaultOnly> >(1024);
96 test<DefaultOnly, std::allocator<DefaultOnly> >(1025);
97 test<DefaultOnly, std::allocator<DefaultOnly> >(2047);
98 test<DefaultOnly, std::allocator<DefaultOnly> >(2048);
99 test<DefaultOnly, std::allocator<DefaultOnly> >(2049);
100 test<DefaultOnly, std::allocator<DefaultOnly> >(4095);
101 test<DefaultOnly, std::allocator<DefaultOnly> >(4096);
102 test<DefaultOnly, std::allocator<DefaultOnly> >(4097);
104 LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095));
106 #if TEST_STD_VER >= 11
107 test<DefaultOnly, min_allocator<DefaultOnly> >(4095);
108 #endif
110 #if TEST_STD_VER > 11
111 test3<DefaultOnly, std::allocator<DefaultOnly>> (1023);
112 test3<int, std::allocator<int>>(1);
113 test3<int, min_allocator<int>> (3);
114 #endif
117 return 0;