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// <list>
10
11// void resize(size_type sz); // constexpr since C++26
12
13#include <list>
14#include <cassert>
15
16#include "test_macros.h"
17#include "DefaultOnly.h"
18#include "min_allocator.h"
19
20TEST_CONSTEXPR_CXX26 bool test() {
21 {
22 std::list<int> l(5, 2);
23 l.resize(new_size: 2);
24 assert(l.size() == 2);
25 assert(std::distance(l.begin(), l.end()) == 2);
26 assert(l == std::list<int>(2, 2));
27 }
28 {
29 std::list<int> l(5, 2);
30 l.resize(new_size: 10);
31 assert(l.size() == 10);
32 assert(std::distance(l.begin(), l.end()) == 10);
33 assert(l.front() == 2);
34 assert(l.back() == 0);
35 }
36#if TEST_STD_VER >= 11
37 if (!TEST_IS_CONSTANT_EVALUATED) {
38 {
39 std::list<DefaultOnly> l(10);
40 l.resize(5);
41 assert(l.size() == 5);
42 assert(std::distance(l.begin(), l.end()) == 5);
43 }
44 {
45 std::list<DefaultOnly> l(10);
46 l.resize(20);
47 assert(l.size() == 20);
48 assert(std::distance(l.begin(), l.end()) == 20);
49 }
50 {
51 std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
52 l.resize(5);
53 assert(l.size() == 5);
54 assert(std::distance(l.begin(), l.end()) == 5);
55 }
56 {
57 std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
58 l.resize(20);
59 assert(l.size() == 20);
60 assert(std::distance(l.begin(), l.end()) == 20);
61 }
62 }
63 {
64 std::list<int, min_allocator<int>> l(5, 2);
65 l.resize(2);
66 assert(l.size() == 2);
67 assert(std::distance(l.begin(), l.end()) == 2);
68 assert((l == std::list<int, min_allocator<int>>(2, 2)));
69 }
70 {
71 std::list<int, min_allocator<int>> l(5, 2);
72 l.resize(10);
73 assert(l.size() == 10);
74 assert(std::distance(l.begin(), l.end()) == 10);
75 assert(l.front() == 2);
76 assert(l.back() == 0);
77 }
78#endif
79
80 return true;
81}
82
83int main(int, char**) {
84 assert(test());
85#if TEST_STD_VER >= 26
86 static_assert(test());
87#endif
88
89 return 0;
90}
91

source code of libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp