xref: /llvm-project/libcxx/test/std/containers/unord/unord.multiset/max_size.pass.cpp (revision fb855eb941b6d740cc6560297d0b4d3201dcaf9f)
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_set>
10 
11 // class unordered_multiset
12 
13 // size_type max_size() const;
14 
15 #include <cassert>
16 #include <limits>
17 #include <type_traits>
18 #include <unordered_set>
19 
20 #include "test_allocator.h"
21 #include "test_macros.h"
22 
main(int,char **)23 int main(int, char**)
24 {
25     {
26       typedef limited_allocator<int, 10> A;
27       typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>,
28                                       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<int, (std::size_t)-1> A;
36       typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>,
37                                       A>
38           C;
39       const C::size_type max_dist =
40           static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
41       C c;
42       assert(c.max_size() <= max_dist);
43       LIBCPP_ASSERT(c.max_size() == max_dist);
44     }
45     {
46       typedef std::unordered_multiset<char> C;
47       const C::size_type max_dist =
48           static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
49       C c;
50       assert(c.max_size() <= max_dist);
51       assert(c.max_size() <= alloc_max_size(c.get_allocator()));
52     }
53 
54   return 0;
55 }
56