xref: /llvm-project/libcxx/test/std/containers/unord/unord.multimap/load_factor.pass.cpp (revision 3cd4531b9ba421d1d096e746d787fe3039a546bb)
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 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
12 //           class Alloc = allocator<pair<const Key, T>>>
13 // class unordered_multimap
14 
15 // float load_factor() const
16 
17 #include <unordered_map>
18 #include <string>
19 #include <cassert>
20 #include <cfloat>
21 #include <cmath>
22 #include <iterator>
23 
24 #include "test_macros.h"
25 #include "min_allocator.h"
26 
main(int,char **)27 int main(int, char**)
28 {
29     {
30         typedef std::unordered_multimap<int, std::string> C;
31         typedef std::pair<int, std::string> P;
32         P a[] =
33         {
34             P(10, "ten"),
35             P(20, "twenty"),
36             P(30, "thirty"),
37             P(40, "forty"),
38             P(50, "fifty"),
39             P(60, "sixty"),
40             P(70, "seventy"),
41             P(80, "eighty"),
42         };
43         const C c(std::begin(a), std::end(a));
44         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
45     }
46     {
47         typedef std::unordered_multimap<int, std::string> C;
48         const C c;
49         assert(c.load_factor() == 0);
50     }
51 #if TEST_STD_VER >= 11
52     {
53         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
54                             min_allocator<std::pair<const int, std::string>>> C;
55         typedef std::pair<int, std::string> P;
56         P a[] =
57         {
58             P(10, "ten"),
59             P(20, "twenty"),
60             P(30, "thirty"),
61             P(40, "forty"),
62             P(50, "fifty"),
63             P(60, "sixty"),
64             P(70, "seventy"),
65             P(80, "eighty"),
66         };
67         const C c(std::begin(a), std::end(a));
68         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
69     }
70     {
71         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
72                             min_allocator<std::pair<const int, std::string>>> C;
73         const C c;
74         assert(c.load_factor() == 0);
75     }
76 #endif
77 
78   return 0;
79 }
80