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