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_map
15 
16 // unordered_map& operator=(initializer_list<value_type> il);
17 
18 #include <unordered_map>
19 #include <string>
20 #include <cassert>
21 #include <cfloat>
22 
23 #include "../../../test_compare.h"
24 #include "../../../test_hash.h"
25 #include "min_allocator.h"
26 
main()27 int main()
28 {
29 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
30     {
31         typedef std::allocator<std::pair<const int, std::string> > A;
32         typedef std::unordered_map<int, std::string,
33                                    test_hash<std::hash<int> >,
34                                    test_compare<std::equal_to<int> >,
35                                    A
36                                    > C;
37         typedef std::pair<int, std::string> P;
38         C c =   {
39                     P(4, "four"),
40                     P(1, "four"),
41                     P(2, "four"),
42                 };
43         c =     {
44                     P(1, "one"),
45                     P(2, "two"),
46                     P(3, "three"),
47                     P(4, "four"),
48                     P(1, "four"),
49                     P(2, "four"),
50                 };
51         assert(c.bucket_count() >= 5);
52         assert(c.size() == 4);
53         assert(c.at(1) == "one");
54         assert(c.at(2) == "two");
55         assert(c.at(3) == "three");
56         assert(c.at(4) == "four");
57         assert(std::distance(c.begin(), c.end()) == c.size());
58         assert(std::distance(c.cbegin(), c.cend()) == c.size());
59         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
60         assert(c.max_load_factor() == 1);
61     }
62 #if __cplusplus >= 201103L
63     {
64         typedef min_allocator<std::pair<const int, std::string> > A;
65         typedef std::unordered_map<int, std::string,
66                                    test_hash<std::hash<int> >,
67                                    test_compare<std::equal_to<int> >,
68                                    A
69                                    > C;
70         typedef std::pair<int, std::string> P;
71         C c =   {
72                     P(4, "four"),
73                     P(1, "four"),
74                     P(2, "four"),
75                 };
76         c =     {
77                     P(1, "one"),
78                     P(2, "two"),
79                     P(3, "three"),
80                     P(4, "four"),
81                     P(1, "four"),
82                     P(2, "four"),
83                 };
84         assert(c.bucket_count() >= 5);
85         assert(c.size() == 4);
86         assert(c.at(1) == "one");
87         assert(c.at(2) == "two");
88         assert(c.at(3) == "three");
89         assert(c.at(4) == "four");
90         assert(std::distance(c.begin(), c.end()) == c.size());
91         assert(std::distance(c.cbegin(), c.cend()) == c.size());
92         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
93         assert(c.max_load_factor() == 1);
94     }
95 #endif
96 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
97 }
98