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_map
14
15// explicit unordered_map(const allocator_type& __a);
16
17#include <unordered_map>
18#include <cassert>
19
20#include "test_macros.h"
21#include "../../../NotConstructible.h"
22#include "../../../test_compare.h"
23#include "../../../test_hash.h"
24#include "test_allocator.h"
25#include "min_allocator.h"
26
27int main(int, char**)
28{
29 {
30 typedef std::unordered_map<NotConstructible, NotConstructible,
31 test_hash<NotConstructible>,
32 test_equal_to<NotConstructible>,
33 test_allocator<std::pair<const NotConstructible,
34 NotConstructible> >
35 > C;
36 C c(test_allocator<std::pair<const NotConstructible, NotConstructible> >(10));
37 LIBCPP_ASSERT(c.bucket_count() == 0);
38 assert(c.hash_function() == test_hash<NotConstructible>());
39 assert(c.key_eq() == test_equal_to<NotConstructible>());
40 assert(c.get_allocator() ==
41 (test_allocator<std::pair<const NotConstructible, NotConstructible> >(10)));
42 assert(c.size() == 0);
43 assert(c.empty());
44 assert(std::distance(c.begin(), c.end()) == 0);
45 assert(c.load_factor() == 0);
46 assert(c.max_load_factor() == 1);
47 }
48#if TEST_STD_VER >= 11
49 {
50 typedef std::unordered_map<NotConstructible, NotConstructible,
51 test_hash<NotConstructible>,
52 test_equal_to<NotConstructible>,
53 min_allocator<std::pair<const NotConstructible,
54 NotConstructible> >
55 > C;
56 C c(min_allocator<std::pair<const NotConstructible, NotConstructible> >{});
57 LIBCPP_ASSERT(c.bucket_count() == 0);
58 assert(c.hash_function() == test_hash<NotConstructible>());
59 assert(c.key_eq() == test_equal_to<NotConstructible>());
60 assert(c.get_allocator() ==
61 (min_allocator<std::pair<const NotConstructible, NotConstructible> >()));
62 assert(c.size() == 0);
63 assert(c.empty());
64 assert(std::distance(c.begin(), c.end()) == 0);
65 assert(c.load_factor() == 0);
66 assert(c.max_load_factor() == 1);
67 }
68 {
69 typedef explicit_allocator<std::pair<const NotConstructible, NotConstructible>> A;
70 typedef std::unordered_map<NotConstructible, NotConstructible,
71 test_hash<NotConstructible>,
72 test_equal_to<NotConstructible>,
73 A
74 > C;
75 C c(A{});
76 LIBCPP_ASSERT(c.bucket_count() == 0);
77 assert(c.hash_function() == test_hash<NotConstructible>());
78 assert(c.key_eq() == test_equal_to<NotConstructible>());
79 assert(c.get_allocator() == A{});
80 assert(c.size() == 0);
81 assert(c.empty());
82 assert(std::distance(c.begin(), c.end()) == 0);
83 assert(c.load_factor() == 0);
84 assert(c.max_load_factor() == 1);
85 }
86#if TEST_STD_VER > 11
87 {
88 typedef NotConstructible T;
89 typedef test_allocator<std::pair<const T, T>> A;
90 typedef test_hash<T> HF;
91 typedef test_equal_to<T> Comp;
92 typedef std::unordered_map<T, T, HF, Comp, A> C;
93
94 A a(10);
95 C c(2, a);
96 LIBCPP_ASSERT(c.bucket_count() == 2);
97 assert(c.hash_function() == HF());
98 assert(c.key_eq() == Comp());
99 assert(c.get_allocator() == a);
100 assert(c.size() == 0);
101 assert(c.empty());
102 assert(std::distance(c.begin(), c.end()) == 0);
103 assert(c.load_factor() == 0);
104 assert(c.max_load_factor() == 1);
105 }
106 {
107 typedef NotConstructible T;
108 typedef test_allocator<std::pair<const T, T>> A;
109 typedef test_hash<T> HF;
110 typedef test_equal_to<T> Comp;
111 typedef std::unordered_map<T, T, HF, Comp, A> C;
112
113 A a(10);
114 HF hf(12);
115 C c(2, hf, a);
116 LIBCPP_ASSERT(c.bucket_count() == 2);
117 assert(c.hash_function() == hf);
118 assert(!(c.hash_function() == HF()));
119 assert(c.key_eq() == Comp());
120 assert(c.get_allocator() == a);
121 assert(c.size() == 0);
122 assert(c.empty());
123 assert(std::distance(c.begin(), c.end()) == 0);
124 assert(c.load_factor() == 0);
125 assert(c.max_load_factor() == 1);
126 }
127#endif
128#endif
129
130 return 0;
131}
132

source code of libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp