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