Vendor import of libc++ trunk r257626:
[freebsd.git] / test / std / containers / unord / unord.multimap / load_factor.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <unordered_map>
11
12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
13 //           class Alloc = allocator<pair<const Key, T>>>
14 // class unordered_multimap
15
16 // float load_factor() const
17
18 #include <unordered_map>
19 #include <string>
20 #include <cassert>
21 #include <cfloat>
22 #include <cmath>
23
24 #include "min_allocator.h"
25
26 int main()
27 {
28     {
29         typedef std::unordered_multimap<int, std::string> C;
30         typedef std::pair<int, std::string> P;
31         P a[] =
32         {
33             P(10, "ten"),
34             P(20, "twenty"),
35             P(30, "thirty"),
36             P(40, "forty"),
37             P(50, "fifty"),
38             P(60, "sixty"),
39             P(70, "seventy"),
40             P(80, "eighty"),
41         };
42         const C c(std::begin(a), std::end(a));
43         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
44     }
45     {
46         typedef std::unordered_multimap<int, std::string> C;
47         typedef std::pair<int, std::string> P;
48         const C c;
49         assert(c.load_factor() == 0);
50     }
51 #if __cplusplus >= 201103L
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         typedef std::pair<int, std::string> P;
74         const C c;
75         assert(c.load_factor() == 0);
76     }
77 #endif
78 }