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_map 15 16// unordered_map(const unordered_map& 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 std::unordered_map<int, std::string, 30 test_hash<std::hash<int> >, 31 test_compare<std::equal_to<int> >, 32 test_allocator<std::pair<const int, std::string> > 33 > C; 34 typedef std::pair<int, std::string> P; 35 P a[] = 36 { 37 P(1, "one"), 38 P(2, "two"), 39 P(3, "three"), 40 P(4, "four"), 41 P(1, "four"), 42 P(2, "four"), 43 }; 44 C c0(a, a + sizeof(a)/sizeof(a[0]), 45 7, 46 test_hash<std::hash<int> >(8), 47 test_compare<std::equal_to<int> >(9), 48 test_allocator<std::pair<const int, std::string> >(10) 49 ); 50 C c = c0; 51 assert(c.bucket_count() == 7); 52 assert(c.size() == 4); 53 assert(c.at(1) == "one"); 54 assert(c.at(2) == "two"); 55 assert(c.at(3) == "three"); 56 assert(c.at(4) == "four"); 57 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 58 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 59 assert(c.get_allocator() == 60 (test_allocator<std::pair<const int, std::string> >(10))); 61 assert(!c.empty()); 62 assert(std::distance(c.begin(), c.end()) == c.size()); 63 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 64 assert(c.load_factor() == (float)c.size()/c.bucket_count()); 65 assert(c.max_load_factor() == 1); 66 } 67#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE 68 { 69 typedef std::unordered_map<int, std::string, 70 test_hash<std::hash<int> >, 71 test_compare<std::equal_to<int> >, 72 other_allocator<std::pair<const int, std::string> > 73 > C; 74 typedef std::pair<int, std::string> P; 75 P a[] = 76 { 77 P(1, "one"), 78 P(2, "two"), 79 P(3, "three"), 80 P(4, "four"), 81 P(1, "four"), 82 P(2, "four"), 83 }; 84 C c0(a, a + sizeof(a)/sizeof(a[0]), 85 7, 86 test_hash<std::hash<int> >(8), 87 test_compare<std::equal_to<int> >(9), 88 other_allocator<std::pair<const int, std::string> >(10) 89 ); 90 C c = c0; 91 assert(c.bucket_count() == 7); 92 assert(c.size() == 4); 93 assert(c.at(1) == "one"); 94 assert(c.at(2) == "two"); 95 assert(c.at(3) == "three"); 96 assert(c.at(4) == "four"); 97 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 98 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 99 assert(c.get_allocator() == 100 (other_allocator<std::pair<const int, std::string> >(-2))); 101 assert(!c.empty()); 102 assert(std::distance(c.begin(), c.end()) == c.size()); 103 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 104 assert(c.load_factor() == (float)c.size()/c.bucket_count()); 105 assert(c.max_load_factor() == 1); 106 } 107#endif 108} 109