blob: 229e79925f23f81eae099fcfd6dc54c03eee43f9 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <unordered_set>
11
12// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13// class Alloc = allocator<Value>>
14// class unordered_set
15
16// unordered_set(unordered_set&& u, const allocator_type& a);
17
18#include <unordered_set>
19#include <cassert>
Howard Hinnantf836d532011-12-02 21:23:14 +000020#include <cfloat>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
22#include "../../../test_compare.h"
23#include "../../../test_hash.h"
Marshall Clow1b921882013-12-03 00:18:10 +000024#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000025#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000026
27int main()
28{
Howard Hinnant73d21a42010-09-04 23:28:19 +000029#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000030 {
31 typedef int P;
32 typedef test_allocator<int> A;
33 typedef std::unordered_set<int,
34 test_hash<std::hash<int> >,
35 test_compare<std::equal_to<int> >,
36 A
37 > C;
38 P a[] =
39 {
40 P(1),
41 P(2),
42 P(3),
43 P(4),
44 P(1),
45 P(2)
46 };
47 C c0(a, a + sizeof(a)/sizeof(a[0]),
48 7,
49 test_hash<std::hash<int> >(8),
50 test_compare<std::equal_to<int> >(9),
51 A(10)
52 );
53 C c(std::move(c0), A(12));
54 assert(c.bucket_count() >= 5);
55 assert(c.size() == 4);
56 assert(c.count(1) == 1);
57 assert(c.count(2) == 1);
58 assert(c.count(3) == 1);
59 assert(c.count(4) == 1);
60 assert(c.hash_function() == test_hash<std::hash<int> >(8));
61 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
62 assert(c.get_allocator() == A(12));
63 assert(!c.empty());
64 assert(std::distance(c.begin(), c.end()) == c.size());
65 assert(std::distance(c.cbegin(), c.cend()) == c.size());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070066 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067 assert(c.max_load_factor() == 1);
68
69 assert(c0.empty());
70 }
71 {
72 typedef int P;
73 typedef test_allocator<int> A;
74 typedef std::unordered_set<int,
75 test_hash<std::hash<int> >,
76 test_compare<std::equal_to<int> >,
77 A
78 > C;
79 P a[] =
80 {
81 P(1),
82 P(2),
83 P(3),
84 P(4),
85 P(1),
86 P(2)
87 };
88 C c0(a, a + sizeof(a)/sizeof(a[0]),
89 7,
90 test_hash<std::hash<int> >(8),
91 test_compare<std::equal_to<int> >(9),
92 A(10)
93 );
94 C c(std::move(c0), A(10));
95 assert(c.bucket_count() >= 5);
96 assert(c.size() == 4);
97 assert(c.count(1) == 1);
98 assert(c.count(2) == 1);
99 assert(c.count(3) == 1);
100 assert(c.count(4) == 1);
101 assert(c.hash_function() == test_hash<std::hash<int> >(8));
102 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
103 assert(c.get_allocator() == A(10));
104 assert(!c.empty());
105 assert(std::distance(c.begin(), c.end()) == c.size());
106 assert(std::distance(c.cbegin(), c.cend()) == c.size());
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700107 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000108 assert(c.max_load_factor() == 1);
109
110 assert(c0.empty());
111 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000112#if __cplusplus >= 201103L
113 {
114 typedef int P;
115 typedef min_allocator<int> A;
116 typedef std::unordered_set<int,
117 test_hash<std::hash<int> >,
118 test_compare<std::equal_to<int> >,
119 A
120 > C;
121 P a[] =
122 {
123 P(1),
124 P(2),
125 P(3),
126 P(4),
127 P(1),
128 P(2)
129 };
130 C c0(a, a + sizeof(a)/sizeof(a[0]),
131 7,
132 test_hash<std::hash<int> >(8),
133 test_compare<std::equal_to<int> >(9),
134 A()
135 );
136 C c(std::move(c0), A());
137 assert(c.bucket_count() >= 5);
138 assert(c.size() == 4);
139 assert(c.count(1) == 1);
140 assert(c.count(2) == 1);
141 assert(c.count(3) == 1);
142 assert(c.count(4) == 1);
143 assert(c.hash_function() == test_hash<std::hash<int> >(8));
144 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
145 assert(c.get_allocator() == A());
146 assert(!c.empty());
147 assert(std::distance(c.begin(), c.end()) == c.size());
148 assert(std::distance(c.cbegin(), c.cend()) == c.size());
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700149 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000150 assert(c.max_load_factor() == 1);
151
152 assert(c0.empty());
153 }
154#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000155#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000156}