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// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
11// <flat_map>
12
13// size_type max_size() const noexcept;
14
15#include <cassert>
16#include <deque>
17#include <flat_map>
18#include <functional>
19#include <limits>
20#include <type_traits>
21#include <vector>
22
23#include "MinSequenceContainer.h"
24#include "test_allocator.h"
25#include "test_macros.h"
26
27int main(int, char**) {
28 {
29 using A1 = limited_allocator<int, 10>;
30 using A2 = limited_allocator<int, 20>;
31 using C = std::flat_map<int, int, std::less<int>, std::vector<int, A1>, std::vector<int, A2>>;
32 ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
33 ASSERT_SAME_TYPE(C::size_type, std::size_t);
34 const C c;
35 ASSERT_NOEXCEPT(c.max_size());
36 ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
37 assert(c.max_size() <= 10);
38 LIBCPP_ASSERT(c.max_size() == 10);
39 }
40 {
41 using A1 = limited_allocator<int, 10>;
42 using A2 = limited_allocator<int, 20>;
43 using C = std::flat_map<int, int, std::less<int>, std::vector<int, A2>, std::vector<int, A1>>;
44 ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
45 ASSERT_SAME_TYPE(C::size_type, std::size_t);
46 const C c;
47 ASSERT_NOEXCEPT(c.max_size());
48 ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
49 assert(c.max_size() <= 10);
50 LIBCPP_ASSERT(c.max_size() == 10);
51 }
52 {
53 using A = limited_allocator<int, (size_t)-1>;
54 using C = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::vector<int, A>>;
55 ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
56 ASSERT_SAME_TYPE(C::size_type, std::size_t);
57 const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
58 const C c;
59 ASSERT_NOEXCEPT(c.max_size());
60 ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
61 assert(c.max_size() <= max_dist);
62 LIBCPP_ASSERT(c.max_size() == max_dist);
63 }
64 {
65 typedef std::flat_map<char, char> C;
66 ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
67 ASSERT_SAME_TYPE(C::size_type, std::size_t);
68 const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
69 const C c;
70 ASSERT_NOEXCEPT(c.max_size());
71 ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
72 assert(c.max_size() <= max_dist);
73 assert(c.max_size() <= alloc_max_size(std::allocator<char>()));
74 }
75 return 0;
76}
77

source code of libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp