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

source code of libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp