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 typedef std::unordered_set<int> C;
26 typedef int P;
27 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
28 const C c(std::begin(arr&: a), std::end(arr&: a));
29 assert(c.bucket_count() >= 5);
30 LIBCPP_ASSERT(c.bucket_size(n: 0) == 0);
31 LIBCPP_ASSERT(c.bucket_size(n: 1) == 1);
32 LIBCPP_ASSERT(c.bucket_size(n: 2) == 1);
33 LIBCPP_ASSERT(c.bucket_size(n: 3) == 1);
34 LIBCPP_ASSERT(c.bucket_size(n: 4) == 1);
35 }
36#if TEST_STD_VER >= 11
37 {
38 typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;
39 typedef int P;
40 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
41 const C c(std::begin(a), std::end(a));
42 assert(c.bucket_count() >= 5);
43 LIBCPP_ASSERT(c.bucket_size(0) == 0);
44 LIBCPP_ASSERT(c.bucket_size(1) == 1);
45 LIBCPP_ASSERT(c.bucket_size(2) == 1);
46 LIBCPP_ASSERT(c.bucket_size(3) == 1);
47 LIBCPP_ASSERT(c.bucket_size(4) == 1);
48 }
49#endif
50
51 return 0;
52}
53

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