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);
12
13#include <list>
14#include <cassert>
15#include "test_macros.h"
16#include "DefaultOnly.h"
17#include "min_allocator.h"
18
19int main(int, char**)
20{
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 {
38 std::list<DefaultOnly> l(10);
39 l.resize(5);
40 assert(l.size() == 5);
41 assert(std::distance(l.begin(), l.end()) == 5);
42 }
43 {
44 std::list<DefaultOnly> l(10);
45 l.resize(20);
46 assert(l.size() == 20);
47 assert(std::distance(l.begin(), l.end()) == 20);
48 }
49 {
50 std::list<int, min_allocator<int>> l(5, 2);
51 l.resize(2);
52 assert(l.size() == 2);
53 assert(std::distance(l.begin(), l.end()) == 2);
54 assert((l == std::list<int, min_allocator<int>>(2, 2)));
55 }
56 {
57 std::list<int, min_allocator<int>> l(5, 2);
58 l.resize(10);
59 assert(l.size() == 10);
60 assert(std::distance(l.begin(), l.end()) == 10);
61 assert(l.front() == 2);
62 assert(l.back() == 0);
63 }
64 {
65 std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
66 l.resize(5);
67 assert(l.size() == 5);
68 assert(std::distance(l.begin(), l.end()) == 5);
69 }
70 {
71 std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
72 l.resize(20);
73 assert(l.size() == 20);
74 assert(std::distance(l.begin(), l.end()) == 20);
75 }
76#endif
77
78 return 0;
79}
80

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