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