copy_alloc.pass.cpp (4033B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 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_multiset 15 16 // unordered_multiset(const unordered_multiset& u, const allocator_type& a); 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_compare.h" 26 #include "../../../test_hash.h" 27 #include "test_allocator.h" 28 #include "min_allocator.h" 29 30 int main() 31 { 32 { 33 typedef std::unordered_multiset<int, 34 test_hash<std::hash<int> >, 35 test_compare<std::equal_to<int> >, 36 test_allocator<int> 37 > C; 38 typedef int P; 39 P a[] = 40 { 41 P(1), 42 P(2), 43 P(3), 44 P(4), 45 P(1), 46 P(2) 47 }; 48 C c0(a, a + sizeof(a)/sizeof(a[0]), 49 7, 50 test_hash<std::hash<int> >(8), 51 test_compare<std::equal_to<int> >(9), 52 test_allocator<int>(10) 53 ); 54 C c(c0, test_allocator<int>(5)); 55 LIBCPP_ASSERT(c.bucket_count() == 7); 56 assert(c.size() == 6); 57 C::const_iterator i = c.cbegin(); 58 assert(*i == 1); 59 ++i; 60 assert(*i == 1); 61 ++i; 62 assert(*i == 2); 63 ++i; 64 assert(*i == 2); 65 ++i; 66 assert(*i == 3); 67 ++i; 68 assert(*i == 4); 69 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 70 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 71 assert(c.get_allocator() == test_allocator<int>(5)); 72 assert(!c.empty()); 73 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 74 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 75 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 76 assert(c.max_load_factor() == 1); 77 } 78 #if TEST_STD_VER >= 11 79 { 80 typedef std::unordered_multiset<int, 81 test_hash<std::hash<int> >, 82 test_compare<std::equal_to<int> >, 83 min_allocator<int> 84 > C; 85 typedef int P; 86 P a[] = 87 { 88 P(1), 89 P(2), 90 P(3), 91 P(4), 92 P(1), 93 P(2) 94 }; 95 C c0(a, a + sizeof(a)/sizeof(a[0]), 96 7, 97 test_hash<std::hash<int> >(8), 98 test_compare<std::equal_to<int> >(9), 99 min_allocator<int>() 100 ); 101 C c(c0, min_allocator<int>()); 102 LIBCPP_ASSERT(c.bucket_count() == 7); 103 assert(c.size() == 6); 104 C::const_iterator i = c.cbegin(); 105 assert(*i == 1); 106 ++i; 107 assert(*i == 1); 108 ++i; 109 assert(*i == 2); 110 ++i; 111 assert(*i == 2); 112 ++i; 113 assert(*i == 3); 114 ++i; 115 assert(*i == 4); 116 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 117 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 118 assert(c.get_allocator() == min_allocator<int>()); 119 assert(!c.empty()); 120 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 121 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 122 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 123 assert(c.max_load_factor() == 1); 124 } 125 #endif 126 }