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
11// void pop_back();
12
13#include <vector>
14#include <cassert>
15
16#include "test_macros.h"
17#include "test_allocator.h"
18#include "min_allocator.h"
19
20TEST_CONSTEXPR_CXX20 bool tests() {
21 {
22 std::vector<int> c;
23 c.push_back(x: 1);
24 assert(c.size() == 1);
25 c.pop_back();
26 assert(c.size() == 0);
27 }
28#if TEST_STD_VER >= 11
29 {
30 std::vector<int, min_allocator<int>> c;
31 c.push_back(1);
32 assert(c.size() == 1);
33 c.pop_back();
34 assert(c.size() == 0);
35 }
36#endif
37
38 { // LWG 526
39 int arr[] = {0, 1, 2, 3, 4};
40 int sz = 5;
41 std::vector<int> c(arr, arr + sz);
42 while (c.size() < c.capacity())
43 c.push_back(x: sz++);
44 c.push_back(x: c.front());
45 assert(c.back() == 0);
46 for (int i = 0; i < sz; ++i)
47 assert(c[i] == i);
48 }
49
50 return true;
51}
52
53int main(int, char**) {
54 tests();
55#if TEST_STD_VER > 17
56 static_assert(tests());
57#endif
58 return 0;
59}
60

source code of libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp