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