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