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// unordered_set(const unordered_set& u);
16
17#include <unordered_set>
18#include <cassert>
19#include <cfloat>
20#include <cmath>
21#include <cstddef>
22
23#include "test_macros.h"
24#include "../../../test_compare.h"
25#include "../../../test_hash.h"
26#include "test_allocator.h"
27#include "min_allocator.h"
28
29int main(int, char**) {
30 {
31 typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, test_allocator<int> > C;
32 typedef int P;
33 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
34 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), test_allocator<int>(10));
35 C c = c0;
36 LIBCPP_ASSERT(c.bucket_count() == 7);
37 assert(c.size() == 4);
38 assert(c.count(1) == 1);
39 assert(c.count(2) == 1);
40 assert(c.count(3) == 1);
41 assert(c.count(4) == 1);
42 assert(c.hash_function() == test_hash<int>(8));
43 assert(c.key_eq() == test_equal_to<int>(9));
44 assert(c.get_allocator() == test_allocator<int>(10));
45 assert(!c.empty());
46 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
47 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
48 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
49 assert(c.max_load_factor() == 1);
50 }
51#if TEST_STD_VER >= 11
52 {
53 typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, other_allocator<int> > C;
54 typedef int P;
55 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
56 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), other_allocator<int>(10));
57 C c = c0;
58 LIBCPP_ASSERT(c.bucket_count() == 7);
59 assert(c.size() == 4);
60 assert(c.count(1) == 1);
61 assert(c.count(2) == 1);
62 assert(c.count(3) == 1);
63 assert(c.count(4) == 1);
64 assert(c.hash_function() == test_hash<int>(8));
65 assert(c.key_eq() == test_equal_to<int>(9));
66 assert(c.get_allocator() == other_allocator<int>(-2));
67 assert(!c.empty());
68 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
69 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
70 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
71 assert(c.max_load_factor() == 1);
72 }
73 {
74 typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, min_allocator<int> > C;
75 typedef int P;
76 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
77 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), min_allocator<int>());
78 C c = c0;
79 LIBCPP_ASSERT(c.bucket_count() == 7);
80 assert(c.size() == 4);
81 assert(c.count(1) == 1);
82 assert(c.count(2) == 1);
83 assert(c.count(3) == 1);
84 assert(c.count(4) == 1);
85 assert(c.hash_function() == test_hash<int>(8));
86 assert(c.key_eq() == test_equal_to<int>(9));
87 assert(c.get_allocator() == min_allocator<int>());
88 assert(!c.empty());
89 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
90 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
91 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
92 assert(c.max_load_factor() == 1);
93 }
94#endif
95
96 return 0;
97}
98

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