BPSectionOrderer: stabilize iteration order and node order
[llvm-project.git] / libcxx / test / std / containers / sequences / vector.bool / reserve.pass.cpp
blobe179fb95aac226054f741854695506564a2856f9
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 // <vector>
10 // vector<bool>
12 // void reserve(size_type n);
14 #include <vector>
15 #include <cassert>
16 #include <stdexcept>
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "test_allocator.h"
22 TEST_CONSTEXPR_CXX20 bool tests()
25 std::vector<bool> v;
26 v.reserve(10);
27 assert(v.capacity() >= 10);
30 std::vector<bool> v(100);
31 assert(v.capacity() >= 100);
32 v.reserve(50);
33 assert(v.size() == 100);
34 assert(v.capacity() >= 100);
35 v.reserve(150);
36 assert(v.size() == 100);
37 assert(v.capacity() >= 150);
39 #if TEST_STD_VER >= 11
41 std::vector<bool, min_allocator<bool>> v;
42 v.reserve(10);
43 assert(v.capacity() >= 10);
46 std::vector<bool, explicit_allocator<bool>> v;
47 v.reserve(10);
48 assert(v.capacity() >= 10);
51 std::vector<bool, min_allocator<bool>> v(100);
52 assert(v.capacity() >= 100);
53 v.reserve(50);
54 assert(v.size() == 100);
55 assert(v.capacity() >= 100);
56 v.reserve(150);
57 assert(v.size() == 100);
58 assert(v.capacity() >= 150);
60 #endif
61 #ifndef TEST_HAS_NO_EXCEPTIONS
62 if (!TEST_IS_CONSTANT_EVALUATED) {
63 std::vector<bool, limited_allocator<bool, 10> > v;
64 v.reserve(5);
65 try {
66 // A typical implementation would allocate chunks of bits.
67 // In libc++ the chunk has the same size as the machine word. It is
68 // reasonable to assume that in practice no implementation would use
69 // 64 kB or larger chunks.
70 v.reserve(10 * 65536);
71 assert(false);
72 } catch (const std::length_error&) {
73 // no-op
75 assert(v.capacity() >= 5);
77 #endif
79 return true;
82 int main(int, char**)
84 tests();
85 #if TEST_STD_VER > 17
86 static_assert(tests());
87 #endif
88 return 0;