1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13 // class Alloc = allocator<Value>>
14 // class unordered_set
16 // template <class InputIterator>
17 // unordered_set(InputIterator first, InputIterator last, size_type n,
18 // const hasher& hf, const key_equal& eql);
20 #include <unordered_set>
26 #include "test_macros.h"
27 #include "test_iterators.h"
28 #include "../../../test_compare.h"
29 #include "../../../test_hash.h"
30 #include "test_allocator.h"
31 #include "min_allocator.h"
36 typedef std::unordered_set<int,
37 test_hash<std::hash<int> >,
38 test_compare<std::equal_to<int> >,
51 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
53 test_hash<std::hash<int> >(8),
54 test_compare<std::equal_to<int> >(9)
56 LIBCPP_ASSERT(c.bucket_count() == 7);
57 assert(c.size() == 4);
58 assert(c.count(1) == 1);
59 assert(c.count(2) == 1);
60 assert(c.count(3) == 1);
61 assert(c.count(4) == 1);
62 assert(c.hash_function() == test_hash<std::hash<int> >(8));
63 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
64 assert(c.get_allocator() == test_allocator<int>());
66 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
67 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
68 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
69 assert(c.max_load_factor() == 1);
71 #if TEST_STD_VER >= 11
73 typedef std::unordered_set<int,
74 test_hash<std::hash<int> >,
75 test_compare<std::equal_to<int> >,
88 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
90 test_hash<std::hash<int> >(8),
91 test_compare<std::equal_to<int> >(9)
93 LIBCPP_ASSERT(c.bucket_count() == 7);
94 assert(c.size() == 4);
95 assert(c.count(1) == 1);
96 assert(c.count(2) == 1);
97 assert(c.count(3) == 1);
98 assert(c.count(4) == 1);
99 assert(c.hash_function() == test_hash<std::hash<int> >(8));
100 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
101 assert(c.get_allocator() == min_allocator<int>());
103 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
104 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
105 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
106 assert(c.max_load_factor() == 1);