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, const value_type& x);
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 {
23 std::vector<bool> v(100);
24 v.resize(new_size: 50, x: 1);
25 assert(v.size() == 50);
26 assert(v.capacity() >= 100);
27 assert(v == std::vector<bool>(50));
28 v.resize(new_size: 200, x: 1);
29 assert(v.size() == 200);
30 assert(v.capacity() >= 200);
31 for (unsigned i = 0; i < 50; ++i)
32 assert(v[i] == 0);
33 for (unsigned i = 50; i < 200; ++i)
34 assert(v[i] == 1);
35 }
36#if TEST_STD_VER >= 11
37 {
38 std::vector<bool, min_allocator<bool>> v(100);
39 v.resize(50, 1);
40 assert(v.size() == 50);
41 assert(v.capacity() >= 100);
42 assert((v == std::vector<bool, min_allocator<bool>>(50)));
43 v.resize(200, 1);
44 assert(v.size() == 200);
45 assert(v.capacity() >= 200);
46 for (unsigned i = 0; i < 50; ++i)
47 assert(v[i] == 0);
48 for (unsigned i = 50; i < 200; ++i)
49 assert(v[i] == 1);
50 }
51#endif
52
53 return true;
54}
55
56int main(int, char**)
57{
58 tests();
59#if TEST_STD_VER > 17
60 static_assert(tests());
61#endif
62 return 0;
63}
64

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