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 max_size() const; |
12 | |
13 | #include <cassert> |
14 | #include <limits> |
15 | #include <type_traits> |
16 | #include <vector> |
17 | |
18 | #include "test_allocator.h" |
19 | #include "test_macros.h" |
20 | |
21 | |
22 | TEST_CONSTEXPR_CXX20 bool test() { |
23 | { |
24 | typedef limited_allocator<int, 10> A; |
25 | typedef std::vector<int, A> C; |
26 | C c; |
27 | assert(c.max_size() <= 10); |
28 | LIBCPP_ASSERT(c.max_size() == 10); |
29 | } |
30 | { |
31 | typedef limited_allocator<int, (std::size_t)-1> A; |
32 | typedef std::vector<int, A> C; |
33 | const C::size_type max_dist = |
34 | static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max()); |
35 | C c; |
36 | assert(c.max_size() <= max_dist); |
37 | LIBCPP_ASSERT(c.max_size() == max_dist); |
38 | } |
39 | { |
40 | typedef std::vector<char> C; |
41 | const C::size_type max_dist = |
42 | static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max()); |
43 | C c; |
44 | assert(c.max_size() <= max_dist); |
45 | assert(c.max_size() <= alloc_max_size(c.get_allocator())); |
46 | } |
47 | |
48 | return true; |
49 | } |
50 | |
51 | int main(int, char**) { |
52 | test(); |
53 | |
54 | #if TEST_STD_VER > 17 |
55 | static_assert(test()); |
56 | #endif |
57 | |
58 | return 0; |
59 | } |
60 | |