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// class vector
12
13// size_type size() const noexcept;
14
15#include <vector>
16#include <cassert>
17
18#include "test_macros.h"
19#include "min_allocator.h"
20
21TEST_CONSTEXPR_CXX20 bool tests() {
22 {
23 typedef std::vector<int> C;
24 C c;
25 ASSERT_NOEXCEPT(c.size());
26 assert(c.size() == 0);
27 c.push_back(x: C::value_type(2));
28 assert(c.size() == 1);
29 c.push_back(x: C::value_type(1));
30 assert(c.size() == 2);
31 c.push_back(x: C::value_type(3));
32 assert(c.size() == 3);
33 c.erase(position: c.begin());
34 assert(c.size() == 2);
35 c.erase(position: c.begin());
36 assert(c.size() == 1);
37 c.erase(position: c.begin());
38 assert(c.size() == 0);
39 }
40#if TEST_STD_VER >= 11
41 {
42 typedef std::vector<int, min_allocator<int>> C;
43 C c;
44 ASSERT_NOEXCEPT(c.size());
45 assert(c.size() == 0);
46 c.push_back(C::value_type(2));
47 assert(c.size() == 1);
48 c.push_back(C::value_type(1));
49 assert(c.size() == 2);
50 c.push_back(C::value_type(3));
51 assert(c.size() == 3);
52 c.erase(c.begin());
53 assert(c.size() == 2);
54 c.erase(c.begin());
55 assert(c.size() == 1);
56 c.erase(c.begin());
57 assert(c.size() == 0);
58 }
59 {
60 typedef std::vector<int, safe_allocator<int>> C;
61 C c;
62 ASSERT_NOEXCEPT(c.size());
63 assert(c.size() == 0);
64 c.push_back(C::value_type(2));
65 assert(c.size() == 1);
66 c.push_back(C::value_type(1));
67 assert(c.size() == 2);
68 c.push_back(C::value_type(3));
69 assert(c.size() == 3);
70 c.erase(c.begin());
71 assert(c.size() == 2);
72 c.erase(c.begin());
73 assert(c.size() == 1);
74 c.erase(c.begin());
75 assert(c.size() == 0);
76 }
77#endif
78
79 return true;
80}
81
82int main(int, char**) {
83 tests();
84#if TEST_STD_VER > 17
85 static_assert(tests());
86#endif
87 return 0;
88}
89

source code of libcxx/test/std/containers/sequences/vector/vector.capacity/size.pass.cpp