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// template <class InputIterator>
16// unordered_multiset(InputIterator first, InputIterator last);
17
18#include <unordered_set>
19#include <cassert>
20#include <cfloat>
21#include <cmath>
22#include <cstddef>
23
24#include "test_macros.h"
25#include "test_iterators.h"
26#include "../../../test_compare.h"
27#include "../../../test_hash.h"
28#include "test_allocator.h"
29#include "min_allocator.h"
30
31int main(int, char**) {
32 {
33 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, test_allocator<int> > C;
34 typedef int P;
35 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
36 C c(cpp17_input_iterator<P*>(a), cpp17_input_iterator<P*>(a + sizeof(a) / sizeof(a[0])));
37 assert(c.bucket_count() >= 7);
38 assert(c.size() == 6);
39 assert(c.count(1) == 2);
40 assert(c.count(2) == 2);
41 assert(c.count(3) == 1);
42 assert(c.count(4) == 1);
43 assert(c.hash_function() == test_hash<int>());
44 assert(c.key_eq() == test_equal_to<int>());
45 assert(c.get_allocator() == test_allocator<int>());
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(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>, min_allocator<int> > C;
55 typedef int P;
56 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
57 C c(cpp17_input_iterator<P*>(a), cpp17_input_iterator<P*>(a + sizeof(a) / sizeof(a[0])));
58 assert(c.bucket_count() >= 7);
59 assert(c.size() == 6);
60 assert(c.count(1) == 2);
61 assert(c.count(2) == 2);
62 assert(c.count(3) == 1);
63 assert(c.count(4) == 1);
64 assert(c.hash_function() == test_hash<int>());
65 assert(c.key_eq() == test_equal_to<int>());
66 assert(c.get_allocator() == min_allocator<int>());
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(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
71 assert(c.max_load_factor() == 1);
72 }
73# if TEST_STD_VER > 11
74 {
75 typedef int T;
76 typedef test_hash<T> HF;
77 typedef test_equal_to<T> Comp;
78 typedef test_allocator<T> A;
79 typedef std::unordered_multiset<T, HF, Comp, A> C;
80 T arr[] = {T(1), T(2), T(3), T(4), T(1), T(2)};
81 A a(42);
82 C c(cpp17_input_iterator<T*>(arr), cpp17_input_iterator<T*>(arr + sizeof(arr) / sizeof(arr[0])), 12, a);
83 assert(c.bucket_count() >= 12);
84 assert(c.size() == 6);
85 assert(c.count(1) == 2);
86 assert(c.count(2) == 2);
87 assert(c.count(3) == 1);
88 assert(c.count(4) == 1);
89 assert(c.hash_function() == HF());
90 assert(c.key_eq() == Comp());
91 assert(c.get_allocator() == a);
92 assert(!(c.get_allocator() == A()));
93 assert(!c.empty());
94 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
95 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
96 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
97 assert(c.max_load_factor() == 1);
98 }
99 {
100 typedef int T;
101 typedef test_hash<T> HF;
102 typedef test_equal_to<T> Comp;
103 typedef test_allocator<T> A;
104 typedef std::unordered_multiset<T, HF, Comp, A> C;
105 T arr[] = {T(1), T(2), T(3), T(4), T(1), T(2)};
106 HF hf(43);
107 A a(42);
108 C c(cpp17_input_iterator<T*>(arr), cpp17_input_iterator<T*>(arr + sizeof(arr) / sizeof(arr[0])), 16, hf, a);
109 assert(c.bucket_count() >= 16);
110 assert(c.size() == 6);
111 assert(c.count(1) == 2);
112 assert(c.count(2) == 2);
113 assert(c.count(3) == 1);
114 assert(c.count(4) == 1);
115 assert(c.hash_function() == hf);
116 assert(!(c.hash_function() == HF()));
117 assert(c.key_eq() == Comp());
118 assert(c.get_allocator() == a);
119 assert(!(c.get_allocator() == A()));
120 assert(!c.empty());
121 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
122 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
123 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
124 assert(c.max_load_factor() == 1);
125 }
126# endif
127#endif
128
129 return 0;
130}
131

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