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// UNSUPPORTED: c++03
10
11// <unordered_set>
12
13// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
14// class Alloc = allocator<Value>>
15// class unordered_multiset
16
17// unordered_multiset(unordered_multiset&& u, const allocator_type& a);
18
19#include <unordered_set>
20#include <cassert>
21#include <cfloat>
22#include <cmath>
23#include <cstddef>
24
25#include "test_macros.h"
26#include "../../../check_consecutive.h"
27#include "../../../test_compare.h"
28#include "../../../test_hash.h"
29#include "test_allocator.h"
30#include "min_allocator.h"
31
32int main(int, char**) {
33 {
34 typedef int P;
35 typedef test_allocator<int> A;
36 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
37 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
38 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
39 C c(std::move(c0), A(12));
40 assert(c.bucket_count() >= 7);
41 assert(c.size() == 6);
42 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 1), end: c.end(), value: 1, count: 2);
43 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 2), end: c.end(), value: 2, count: 2);
44 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 3), end: c.end(), value: 3, count: 1);
45 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 4), end: c.end(), value: 4, count: 1);
46 assert(c.hash_function() == test_hash<int>(8));
47 assert(c.key_eq() == test_equal_to<int>(9));
48 assert(c.get_allocator() == A(12));
49 assert(!c.empty());
50 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
51 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
52 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
53 assert(c.max_load_factor() == 1);
54
55 assert(c0.empty());
56 }
57 {
58 typedef int P;
59 typedef test_allocator<int> A;
60 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
61 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
62 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
63 C c(std::move(c0), A(10));
64 LIBCPP_ASSERT(c.bucket_count() == 7);
65 assert(c.size() == 6);
66 assert(c.count(1) == 2);
67 assert(c.count(2) == 2);
68 assert(c.count(3) == 1);
69 assert(c.count(4) == 1);
70 assert(c.hash_function() == test_hash<int>(8));
71 assert(c.key_eq() == test_equal_to<int>(9));
72 assert(c.get_allocator() == A(10));
73 assert(!c.empty());
74 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
75 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
76 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
77 assert(c.max_load_factor() == 1);
78
79 assert(c0.empty());
80 }
81 {
82 typedef int P;
83 typedef min_allocator<int> A;
84 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
85 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
86 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A());
87 C c(std::move(c0), A());
88 assert(c.bucket_count() >= 7);
89 assert(c.size() == 6);
90 assert(c.count(1) == 2);
91 assert(c.count(2) == 2);
92 assert(c.count(3) == 1);
93 assert(c.count(4) == 1);
94 assert(c.hash_function() == test_hash<int>(8));
95 assert(c.key_eq() == test_equal_to<int>(9));
96 assert(c.get_allocator() == A());
97 assert(!c.empty());
98 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
99 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
100 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
101 assert(c.max_load_factor() == 1);
102
103 assert(c0.empty());
104 }
105 {
106 typedef int P;
107 typedef min_allocator<int> A;
108 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
109 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
110 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A());
111 C c(std::move(c0), A());
112 LIBCPP_ASSERT(c.bucket_count() == 7);
113 assert(c.size() == 6);
114 assert(c.count(1) == 2);
115 assert(c.count(2) == 2);
116 assert(c.count(3) == 1);
117 assert(c.count(4) == 1);
118 assert(c.hash_function() == test_hash<int>(8));
119 assert(c.key_eq() == test_equal_to<int>(9));
120 assert(c.get_allocator() == A());
121 assert(!c.empty());
122 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
123 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
124 assert(std::fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
125 assert(c.max_load_factor() == 1);
126
127 assert(c0.empty());
128 }
129
130 return 0;
131}
132

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