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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <vector> |
10 | // vector<bool> |
11 | |
12 | // void resize(size_type sz); |
13 | |
14 | #include <vector> |
15 | #include <cassert> |
16 | |
17 | #include "test_macros.h" |
18 | #include "min_allocator.h" |
19 | |
20 | TEST_CONSTEXPR_CXX20 bool tests() |
21 | { |
22 | { |
23 | std::vector<bool> v(100); |
24 | v.resize(new_size: 50); |
25 | assert(v.size() == 50); |
26 | assert(v.capacity() >= 100); |
27 | v.resize(new_size: 200); |
28 | assert(v.size() == 200); |
29 | assert(v.capacity() >= 200); |
30 | v.reserve(n: 400); |
31 | v.resize(new_size: 300); // check the case when resizing and we already have room |
32 | assert(v.size() == 300); |
33 | assert(v.capacity() >= 400); |
34 | } |
35 | #if TEST_STD_VER >= 11 |
36 | { |
37 | std::vector<bool, explicit_allocator<bool>> v; |
38 | v.resize(10); |
39 | assert(v.size() == 10); |
40 | assert(v.capacity() >= 10); |
41 | } |
42 | { |
43 | std::vector<bool, min_allocator<bool>> v(100); |
44 | v.resize(50); |
45 | assert(v.size() == 50); |
46 | assert(v.capacity() >= 100); |
47 | v.resize(200); |
48 | assert(v.size() == 200); |
49 | assert(v.capacity() >= 200); |
50 | v.reserve(400); |
51 | v.resize(300); // check the case when resizing and we already have room |
52 | assert(v.size() == 300); |
53 | assert(v.capacity() >= 400); |
54 | } |
55 | #endif |
56 | |
57 | return true; |
58 | } |
59 | |
60 | int main(int, char**) |
61 | { |
62 | tests(); |
63 | #if TEST_STD_VER > 17 |
64 | static_assert(tests()); |
65 | #endif |
66 | return 0; |
67 | } |
68 | |