| 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_set |
| 14 | |
| 15 | // unordered_set(); |
| 16 | |
| 17 | #include <unordered_set> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | #include "../../../NotConstructible.h" |
| 22 | #include "../../../test_compare.h" |
| 23 | #include "../../../test_hash.h" |
| 24 | #include "test_allocator.h" |
| 25 | #include "min_allocator.h" |
| 26 | |
| 27 | int main(int, char**) { |
| 28 | { |
| 29 | typedef std::unordered_set<NotConstructible, |
| 30 | test_hash<NotConstructible>, |
| 31 | test_equal_to<NotConstructible>, |
| 32 | test_allocator<NotConstructible> > |
| 33 | C; |
| 34 | C c; |
| 35 | LIBCPP_ASSERT(c.bucket_count() == 0); |
| 36 | assert(c.hash_function() == test_hash<NotConstructible>()); |
| 37 | assert(c.key_eq() == test_equal_to<NotConstructible>()); |
| 38 | assert(c.get_allocator() == (test_allocator<NotConstructible>())); |
| 39 | assert(c.size() == 0); |
| 40 | assert(c.empty()); |
| 41 | assert(std::distance(c.begin(), c.end()) == 0); |
| 42 | assert(c.load_factor() == 0); |
| 43 | assert(c.max_load_factor() == 1); |
| 44 | } |
| 45 | #if TEST_STD_VER >= 11 |
| 46 | { |
| 47 | typedef std::unordered_set<NotConstructible, |
| 48 | test_hash<NotConstructible>, |
| 49 | test_equal_to<NotConstructible>, |
| 50 | min_allocator<NotConstructible> > |
| 51 | C; |
| 52 | C c; |
| 53 | LIBCPP_ASSERT(c.bucket_count() == 0); |
| 54 | assert(c.hash_function() == test_hash<NotConstructible>()); |
| 55 | assert(c.key_eq() == test_equal_to<NotConstructible>()); |
| 56 | assert(c.get_allocator() == (min_allocator<NotConstructible>())); |
| 57 | assert(c.size() == 0); |
| 58 | assert(c.empty()); |
| 59 | assert(std::distance(c.begin(), c.end()) == 0); |
| 60 | assert(c.load_factor() == 0); |
| 61 | assert(c.max_load_factor() == 1); |
| 62 | } |
| 63 | { |
| 64 | typedef explicit_allocator<NotConstructible> A; |
| 65 | typedef std::unordered_set<NotConstructible, test_hash<NotConstructible>, test_equal_to<NotConstructible>, A > C; |
| 66 | { |
| 67 | C c; |
| 68 | LIBCPP_ASSERT(c.bucket_count() == 0); |
| 69 | assert(c.hash_function() == test_hash<NotConstructible>()); |
| 70 | assert(c.key_eq() == test_equal_to<NotConstructible>()); |
| 71 | assert(c.get_allocator() == A()); |
| 72 | assert(c.size() == 0); |
| 73 | assert(c.empty()); |
| 74 | assert(std::distance(c.begin(), c.end()) == 0); |
| 75 | assert(c.load_factor() == 0); |
| 76 | assert(c.max_load_factor() == 1); |
| 77 | } |
| 78 | { |
| 79 | A a; |
| 80 | C c(a); |
| 81 | LIBCPP_ASSERT(c.bucket_count() == 0); |
| 82 | assert(c.hash_function() == test_hash<NotConstructible>()); |
| 83 | assert(c.key_eq() == test_equal_to<NotConstructible>()); |
| 84 | assert(c.get_allocator() == a); |
| 85 | assert(c.size() == 0); |
| 86 | assert(c.empty()); |
| 87 | assert(std::distance(c.begin(), c.end()) == 0); |
| 88 | assert(c.load_factor() == 0); |
| 89 | assert(c.max_load_factor() == 1); |
| 90 | } |
| 91 | } |
| 92 | { |
| 93 | std::unordered_set<int> c = {}; |
| 94 | LIBCPP_ASSERT(c.bucket_count() == 0); |
| 95 | assert(c.size() == 0); |
| 96 | assert(c.empty()); |
| 97 | assert(std::distance(c.begin(), c.end()) == 0); |
| 98 | assert(c.load_factor() == 0); |
| 99 | assert(c.max_load_factor() == 1); |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |