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

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