1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
15 // void reserve(size_type n);
17 #include <unordered_map>
21 #include "test_macros.h"
22 #include "min_allocator.h"
27 assert(c
.size() == 4);
28 assert(c
.at(1) == "one");
29 assert(c
.at(2) == "two");
30 assert(c
.at(3) == "three");
31 assert(c
.at(4) == "four");
34 void reserve_invariant(std::size_t n
) // LWG #2156
36 for (std::size_t i
= 0; i
< n
; ++i
)
38 std::unordered_map
<std::size_t, size_t> c
;
40 std::size_t buckets
= c
.bucket_count();
41 for (std::size_t j
= 0; j
< i
; ++j
)
44 assert(buckets
== c
.bucket_count());
52 typedef std::unordered_map
<int, std::string
> C
;
53 typedef std::pair
<int, std::string
> P
;
63 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
65 assert(c
.bucket_count() >= 5);
67 LIBCPP_ASSERT(c
.bucket_count() == 5);
71 assert(c
.bucket_count() >= 2);
74 assert(c
.bucket_count() >= 16);
77 #if TEST_STD_VER >= 11
79 typedef std::unordered_map
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
80 min_allocator
<std::pair
<const int, std::string
>>> C
;
81 typedef std::pair
<int, std::string
> P
;
91 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
93 assert(c
.bucket_count() >= 5);
95 LIBCPP_ASSERT(c
.bucket_count() == 5);
99 assert(c
.bucket_count() >= 2);
102 assert(c
.bucket_count() >= 16);
106 reserve_invariant(20);