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,
19 // const allocator_type& a);
21 #include <unordered_set>
27 #include "test_macros.h"
28 #include "test_iterators.h"
29 #include "../../../test_compare.h"
30 #include "../../../test_hash.h"
31 #include "test_allocator.h"
32 #include "min_allocator.h"
37 typedef std::unordered_set<int,
38 test_hash<std::hash<int> >,
39 test_compare<std::equal_to<int> >,
52 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
54 test_hash<std::hash<int> >(8),
55 test_compare<std::equal_to<int> >(9),
56 test_allocator<int>(10)
58 LIBCPP_ASSERT(c.bucket_count() == 7);
59 assert(c.size() == 4);
60 assert(c.count(1) == 1);
61 assert(c.count(2) == 1);
62 assert(c.count(3) == 1);
63 assert(c.count(4) == 1);
64 assert(c.hash_function() == test_hash<std::hash<int> >(8));
65 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
66 assert(c.get_allocator() == test_allocator<int>(10));
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(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
71 assert(c.max_load_factor() == 1);
73 #if TEST_STD_VER >= 11
75 typedef std::unordered_set<int,
76 test_hash<std::hash<int> >,
77 test_compare<std::equal_to<int> >,
90 C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])),
92 test_hash<std::hash<int> >(8),
93 test_compare<std::equal_to<int> >(9),
96 LIBCPP_ASSERT(c.bucket_count() == 7);
97 assert(c.size() == 4);
98 assert(c.count(1) == 1);
99 assert(c.count(2) == 1);
100 assert(c.count(3) == 1);
101 assert(c.count(4) == 1);
102 assert(c.hash_function() == test_hash<std::hash<int> >(8));
103 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
104 assert(c.get_allocator() == min_allocator<int>());
106 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
107 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
108 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
109 assert(c.max_load_factor() == 1);