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

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