assign_copy.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===// 2// 3// ��������������������The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <unordered_map> 11 12// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 13// class Alloc = allocator<pair<const Key, T>>> 14// class unordered_multimap 15 16// unordered_multimap& operator=(const unordered_multimap& u); 17 18#include <unordered_map> 19#include <string> 20#include <cassert> 21 22#include "../../../test_compare.h" 23#include "../../../test_hash.h" 24#include "../../../test_allocator.h" 25 26int main() 27{ 28 { 29 typedef test_allocator<std::pair<const int, std::string> > A; 30 typedef std::unordered_multimap<int, std::string, 31 test_hash<std::hash<int> >, 32 test_compare<std::equal_to<int> >, 33 A 34 > C; 35 typedef std::pair<int, std::string> P; 36 P a[] = 37 { 38 P(1, "one"), 39 P(2, "two"), 40 P(3, "three"), 41 P(4, "four"), 42 P(1, "four"), 43 P(2, "four"), 44 }; 45 C c0(a, a + sizeof(a)/sizeof(a[0]), 46 7, 47 test_hash<std::hash<int> >(8), 48 test_compare<std::equal_to<int> >(9), 49 A(10) 50 ); 51 C c(a, a + 2, 52 7, 53 test_hash<std::hash<int> >(2), 54 test_compare<std::equal_to<int> >(3), 55 A(4) 56 ); 57 c = c0; 58 assert(c.bucket_count() == 7); 59 assert(c.size() == 6); 60 C::const_iterator i = c.cbegin(); 61 assert(i->first == 1); 62 assert(i->second == "one"); 63 ++i; 64 assert(i->first == 1); 65 assert(i->second == "four"); 66 ++i; 67 assert(i->first == 2); 68 assert(i->second == "two"); 69 ++i; 70 assert(i->first == 2); 71 assert(i->second == "four"); 72 ++i; 73 assert(i->first == 3); 74 assert(i->second == "three"); 75 ++i; 76 assert(i->first == 4); 77 assert(i->second == "four"); 78 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 79 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 80 assert(c.get_allocator() == A(4)); 81 assert(!c.empty()); 82 assert(std::distance(c.begin(), c.end()) == c.size()); 83 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 84 assert(c.load_factor() == (float)c.size()/c.bucket_count()); 85 assert(c.max_load_factor() == 1); 86 } 87 { 88 typedef other_allocator<std::pair<const int, std::string> > A; 89 typedef std::unordered_multimap<int, std::string, 90 test_hash<std::hash<int> >, 91 test_compare<std::equal_to<int> >, 92 A 93 > C; 94 typedef std::pair<int, std::string> P; 95 P a[] = 96 { 97 P(1, "one"), 98 P(2, "two"), 99 P(3, "three"), 100 P(4, "four"), 101 P(1, "four"), 102 P(2, "four"), 103 }; 104 C c0(a, a + sizeof(a)/sizeof(a[0]), 105 7, 106 test_hash<std::hash<int> >(8), 107 test_compare<std::equal_to<int> >(9), 108 A(10) 109 ); 110 C c(a, a + 2, 111 7, 112 test_hash<std::hash<int> >(2), 113 test_compare<std::equal_to<int> >(3), 114 A(4) 115 ); 116 c = c0; 117 assert(c.bucket_count() >= 7); 118 assert(c.size() == 6); 119 C::const_iterator i = c.cbegin(); 120 assert(i->first == 1); 121 assert(i->second == "one"); 122 ++i; 123 assert(i->first == 1); 124 assert(i->second == "four"); 125 ++i; 126 assert(i->first == 2); 127 assert(i->second == "two"); 128 ++i; 129 assert(i->first == 2); 130 assert(i->second == "four"); 131 ++i; 132 assert(i->first == 3); 133 assert(i->second == "three"); 134 ++i; 135 assert(i->first == 4); 136 assert(i->second == "four"); 137 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 138 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 139 assert(c.get_allocator() == A(10)); 140 assert(!c.empty()); 141 assert(std::distance(c.begin(), c.end()) == c.size()); 142 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 143 assert(c.load_factor() == (float)c.size()/c.bucket_count()); 144 assert(c.max_load_factor() == 1); 145 } 146} 147