| 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_set> |
| 12 | |
| 13 | // size_type max_size() const noexcept; |
| 14 | |
| 15 | #include <cassert> |
| 16 | #include <deque> |
| 17 | #include <flat_set> |
| 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 | |
| 27 | void test() { |
| 28 | { |
| 29 | using A1 = limited_allocator<int, 10>; |
| 30 | using C = std::flat_multiset<int, std::less<int>, std::vector<int, A1>>; |
| 31 | ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t); |
| 32 | ASSERT_SAME_TYPE(C::size_type, std::size_t); |
| 33 | const C c; |
| 34 | ASSERT_NOEXCEPT(c.max_size()); |
| 35 | ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type); |
| 36 | assert(c.max_size() <= 10); |
| 37 | LIBCPP_ASSERT(c.max_size() == 10); |
| 38 | } |
| 39 | { |
| 40 | using A = limited_allocator<int, (size_t)-1>; |
| 41 | using C = std::flat_multiset<int, std::less<int>, std::vector<int, A>>; |
| 42 | ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t); |
| 43 | ASSERT_SAME_TYPE(C::size_type, std::size_t); |
| 44 | const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max()); |
| 45 | const C c; |
| 46 | ASSERT_NOEXCEPT(c.max_size()); |
| 47 | ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type); |
| 48 | assert(c.max_size() <= max_dist); |
| 49 | LIBCPP_ASSERT(c.max_size() == max_dist); |
| 50 | } |
| 51 | { |
| 52 | typedef std::flat_multiset<char> C; |
| 53 | ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t); |
| 54 | ASSERT_SAME_TYPE(C::size_type, std::size_t); |
| 55 | const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max()); |
| 56 | const C c; |
| 57 | ASSERT_NOEXCEPT(c.max_size()); |
| 58 | ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type); |
| 59 | assert(c.max_size() <= max_dist); |
| 60 | assert(c.max_size() <= alloc_max_size(std::allocator<char>())); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | int main(int, char**) { |
| 65 | test(); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |