Debian Codegraph @

libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp

raw
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 // size_type capacity() const;
12
13 #include <vector>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "min_allocator.h"
18 #include "asan_testing.h"
19
20 TEST_CONSTEXPR_CXX20 bool tests()
21 {
22 {
23 std::vector<int> v;
24 assert(v.capacity() == 0);
25 assert(is_contiguous_container_asan_correct(v));
26 }
27 {
28 std::vector<int> v(100);
29 assert(v.capacity() == 100);
30 v.push_back(0);
31 assert(v.capacity() > 101);
32 assert(is_contiguous_container_asan_correct(v));
33 }
34 #if TEST_STD_VER >= 11
35 {
36 std::vector<int, min_allocator<int>> v;
37 assert(v.capacity() == 0);
38 assert(is_contiguous_container_asan_correct(v));
39 }
40 {
41 std::vector<int, min_allocator<int>> v(100);
42 assert(v.capacity() == 100);
43 v.push_back(0);
44 assert(v.capacity() > 101);
45 assert(is_contiguous_container_asan_correct(v));
46 }
47 #endif
48
49 return true;
50 }
51
52 int main(int, char**)
53 {
54 tests();
55 #if TEST_STD_VER > 17
56 static_assert(tests());
57 #endif
58 return 0;
59 }