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

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