assign_copy.pass.cpp revision f836d531b4146465342939fe32ae47d157ee07b2
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_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_map 15 16// unordered_map& operator=(const unordered_map& u); 17 18#include <unordered_map> 19#include <string> 20#include <cassert> 21#include <cfloat> 22 23#include "../../../test_compare.h" 24#include "../../../test_hash.h" 25#include "../../../test_allocator.h" 26 27int main() 28{ 29 { 30 typedef test_allocator<std::pair<const int, std::string> > A; 31 typedef std::unordered_map<int, std::string, 32 test_hash<std::hash<int> >, 33 test_compare<std::equal_to<int> >, 34 A 35 > C; 36 typedef std::pair<int, std::string> P; 37 P a[] = 38 { 39 P(1, "one"), 40 P(2, "two"), 41 P(3, "three"), 42 P(4, "four"), 43 P(1, "four"), 44 P(2, "four"), 45 }; 46 C c0(a, a + sizeof(a)/sizeof(a[0]), 47 7, 48 test_hash<std::hash<int> >(8), 49 test_compare<std::equal_to<int> >(9), 50 A(10) 51 ); 52 C c(a, a + 2, 53 7, 54 test_hash<std::hash<int> >(2), 55 test_compare<std::equal_to<int> >(3), 56 A(4) 57 ); 58 c = c0; 59 assert(c.bucket_count() == 7); 60 assert(c.size() == 4); 61 assert(c.at(1) == "one"); 62 assert(c.at(2) == "two"); 63 assert(c.at(3) == "three"); 64 assert(c.at(4) == "four"); 65 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 66 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 67 assert(c.get_allocator() == A(4)); 68 assert(!c.empty()); 69 assert(std::distance(c.begin(), c.end()) == c.size()); 70 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 71 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 72 assert(c.max_load_factor() == 1); 73 } 74 { 75 typedef other_allocator<std::pair<const int, std::string> > A; 76 typedef std::unordered_map<int, std::string, 77 test_hash<std::hash<int> >, 78 test_compare<std::equal_to<int> >, 79 A 80 > C; 81 typedef std::pair<int, std::string> P; 82 P a[] = 83 { 84 P(1, "one"), 85 P(2, "two"), 86 P(3, "three"), 87 P(4, "four"), 88 P(1, "four"), 89 P(2, "four"), 90 }; 91 C c0(a, a + sizeof(a)/sizeof(a[0]), 92 7, 93 test_hash<std::hash<int> >(8), 94 test_compare<std::equal_to<int> >(9), 95 A(10) 96 ); 97 C c(a, a + 2, 98 7, 99 test_hash<std::hash<int> >(2), 100 test_compare<std::equal_to<int> >(3), 101 A(4) 102 ); 103 c = c0; 104 assert(c.bucket_count() >= 5); 105 assert(c.size() == 4); 106 assert(c.at(1) == "one"); 107 assert(c.at(2) == "two"); 108 assert(c.at(3) == "three"); 109 assert(c.at(4) == "four"); 110 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 111 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 112 assert(c.get_allocator() == A(10)); 113 assert(!c.empty()); 114 assert(std::distance(c.begin(), c.end()) == c.size()); 115 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 116 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 117 assert(c.max_load_factor() == 1); 118 } 119} 120