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// <list>
10
11// size_type max_size() const noexcept
12
13#include <cassert>
14#include <limits>
15#include <list>
16#include <type_traits>
17
18#include "test_allocator.h"
19#include "test_macros.h"
20
21int main(int, char**) {
22 {
23 typedef limited_allocator<int, 10> A;
24 typedef std::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::list<int, A> C;
32 const C::size_type max_dist =
33 static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
34 C c;
35 assert(c.max_size() <= max_dist);
36 LIBCPP_ASSERT(c.max_size() == max_dist);
37 }
38 {
39 typedef std::list<char> C;
40 const C::size_type max_dist =
41 static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
42 C c;
43 assert(c.max_size() <= max_dist);
44 assert(c.max_size() <= alloc_max_size(c.get_allocator()));
45 }
46
47 return 0;
48}
49

source code of libcxx/test/std/containers/sequences/list/list.capacity/max_size.pass.cpp