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_set>
10
11// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
12// class Alloc = allocator<Value>>
13// class unordered_set
14
15// size_type bucket_size(size_type n) const
16
17#include <unordered_set>
18#include <cassert>
19
20#include "test_macros.h"
21#include "min_allocator.h"
22
23int main(int, char**)
24{
25 {
26 typedef std::unordered_set<int> C;
27 typedef int P;
28 P a[] =
29 {
30 P(1),
31 P(2),
32 P(3),
33 P(4),
34 P(1),
35 P(2)
36 };
37 const C c(std::begin(arr&: a), std::end(arr&: a));
38 assert(c.bucket_count() >= 5);
39 LIBCPP_ASSERT(c.bucket_size(n: 0) == 0);
40 LIBCPP_ASSERT(c.bucket_size(n: 1) == 1);
41 LIBCPP_ASSERT(c.bucket_size(n: 2) == 1);
42 LIBCPP_ASSERT(c.bucket_size(n: 3) == 1);
43 LIBCPP_ASSERT(c.bucket_size(n: 4) == 1);
44 }
45#if TEST_STD_VER >= 11
46 {
47 typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;
48 typedef int P;
49 P a[] =
50 {
51 P(1),
52 P(2),
53 P(3),
54 P(4),
55 P(1),
56 P(2)
57 };
58 const C c(std::begin(a), std::end(a));
59 assert(c.bucket_count() >= 5);
60 LIBCPP_ASSERT(c.bucket_size(0) == 0);
61 LIBCPP_ASSERT(c.bucket_size(1) == 1);
62 LIBCPP_ASSERT(c.bucket_size(2) == 1);
63 LIBCPP_ASSERT(c.bucket_size(3) == 1);
64 LIBCPP_ASSERT(c.bucket_size(4) == 1);
65 }
66#endif
67
68 return 0;
69}
70

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