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
27int main(int, char**) {
28 {
29 typedef std::unordered_multimap<int, std::string> C;
30 typedef std::pair<int, std::string> P;
31 P a[] = {
32 P(10, "ten"),
33 P(20, "twenty"),
34 P(30, "thirty"),
35 P(40, "forty"),
36 P(50, "fifty"),
37 P(60, "sixty"),
38 P(70, "seventy"),
39 P(80, "eighty"),
40 };
41 const C c(std::begin(arr&: a), std::end(arr&: a));
42 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
43 }
44 {
45 typedef std::unordered_multimap<int, std::string> C;
46 const C c;
47 assert(c.load_factor() == 0);
48 }
49#if TEST_STD_VER >= 11
50 {
51 typedef std::unordered_multimap<int,
52 std::string,
53 std::hash<int>,
54 std::equal_to<int>,
55 min_allocator<std::pair<const int, std::string>>>
56 C;
57 typedef std::pair<int, std::string> P;
58 P a[] = {
59 P(10, "ten"),
60 P(20, "twenty"),
61 P(30, "thirty"),
62 P(40, "forty"),
63 P(50, "fifty"),
64 P(60, "sixty"),
65 P(70, "seventy"),
66 P(80, "eighty"),
67 };
68 const C c(std::begin(a), std::end(a));
69 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
70 }
71 {
72 typedef std::unordered_multimap<int,
73 std::string,
74 std::hash<int>,
75 std::equal_to<int>,
76 min_allocator<std::pair<const int, std::string>>>
77 C;
78 const C c;
79 assert(c.load_factor() == 0);
80 }
81#endif
82
83 return 0;
84}
85

source code of libcxx/test/std/containers/unord/unord.multimap/load_factor.pass.cpp