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_multimap
14
15// size_type bucket_size(size_type n) const
16
17#include <unordered_map>
18#include <string>
19#include <cassert>
20#include <iterator>
21
22#include "test_macros.h"
23#include "min_allocator.h"
24
25int main(int, char**) {
26 {
27 typedef std::unordered_multimap<int, std::string> C;
28 typedef std::pair<int, std::string> P;
29 P a[] = {
30 P(1, "one"),
31 P(2, "two"),
32 P(3, "three"),
33 P(4, "four"),
34 P(1, "four"),
35 P(2, "four"),
36 };
37 const C c(std::begin(arr&: a), std::end(arr&: a));
38 assert(c.bucket_count() >= 7);
39 LIBCPP_ASSERT(c.bucket_size(n: 0) == 0);
40 LIBCPP_ASSERT(c.bucket_size(n: 1) == 2);
41 LIBCPP_ASSERT(c.bucket_size(n: 2) == 2);
42 LIBCPP_ASSERT(c.bucket_size(n: 3) == 1);
43 LIBCPP_ASSERT(c.bucket_size(n: 4) == 1);
44 LIBCPP_ASSERT(c.bucket_size(n: 5) == 0);
45 LIBCPP_ASSERT(c.bucket_size(n: 6) == 0);
46 }
47#if TEST_STD_VER >= 11
48 {
49 typedef std::unordered_multimap<int,
50 std::string,
51 std::hash<int>,
52 std::equal_to<int>,
53 min_allocator<std::pair<const int, std::string>>>
54 C;
55 typedef std::pair<int, std::string> P;
56 P a[] = {
57 P(1, "one"),
58 P(2, "two"),
59 P(3, "three"),
60 P(4, "four"),
61 P(1, "four"),
62 P(2, "four"),
63 };
64 const C c(std::begin(a), std::end(a));
65 assert(c.bucket_count() >= 7);
66 LIBCPP_ASSERT(c.bucket_size(0) == 0);
67 LIBCPP_ASSERT(c.bucket_size(1) == 2);
68 LIBCPP_ASSERT(c.bucket_size(2) == 2);
69 LIBCPP_ASSERT(c.bucket_size(3) == 1);
70 LIBCPP_ASSERT(c.bucket_size(4) == 1);
71 LIBCPP_ASSERT(c.bucket_size(5) == 0);
72 LIBCPP_ASSERT(c.bucket_size(6) == 0);
73 }
74#endif
75
76 return 0;
77}
78

source code of libcxx/test/std/containers/unord/unord.multimap/bucket_size.pass.cpp