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