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<bool> C; |
25 | C c; |
26 | ASSERT_NOEXCEPT(c.size()); |
27 | assert(c.size() == 0); |
28 | c.push_back(x: false); |
29 | assert(c.size() == 1); |
30 | c.push_back(x: true); |
31 | assert(c.size() == 2); |
32 | c.push_back(x: false); |
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<bool, min_allocator<bool>> C; |
44 | C c; |
45 | ASSERT_NOEXCEPT(c.size()); |
46 | assert(c.size() == 0); |
47 | c.push_back(false); |
48 | assert(c.size() == 1); |
49 | c.push_back(true); |
50 | assert(c.size() == 2); |
51 | c.push_back(false); |
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 | #endif |
61 | |
62 | return true; |
63 | } |
64 | |
65 | int main(int, char**) |
66 | { |
67 | tests(); |
68 | #if TEST_STD_VER > 17 |
69 | static_assert(tests()); |
70 | #endif |
71 | return 0; |
72 | } |
73 | |