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_multimap 15 16// unordered_multimap& operator=(initializer_list<value_type> il); 17 18#include <unordered_map> 19#include <string> 20#include <cassert> 21#include <cfloat> 22#include <cstddef> 23 24#include "../../../test_compare.h" 25#include "../../../test_hash.h" 26#include "test_allocator.h" 27#include "min_allocator.h" 28 29int main() 30{ 31#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 32 { 33 typedef test_allocator<std::pair<const int, std::string> > A; 34 typedef std::unordered_multimap<int, std::string, 35 test_hash<std::hash<int> >, 36 test_compare<std::equal_to<int> >, 37 A 38 > C; 39 typedef std::pair<int, std::string> P; 40 C c = { 41 P(4, "four"), 42 P(1, "four"), 43 P(2, "four"), 44 }; 45 c = { 46 P(1, "one"), 47 P(2, "two"), 48 P(3, "three"), 49 P(4, "four"), 50 P(1, "four"), 51 P(2, "four"), 52 }; 53 assert(c.bucket_count() >= 7); 54 assert(c.size() == 6); 55 typedef std::pair<C::const_iterator, C::const_iterator> Eq; 56 Eq eq = c.equal_range(1); 57 assert(std::distance(eq.first, eq.second) == 2); 58 C::const_iterator i = eq.first; 59 assert(i->first == 1); 60 assert(i->second == "one"); 61 ++i; 62 assert(i->first == 1); 63 assert(i->second == "four"); 64 eq = c.equal_range(2); 65 assert(std::distance(eq.first, eq.second) == 2); 66 i = eq.first; 67 assert(i->first == 2); 68 assert(i->second == "two"); 69 ++i; 70 assert(i->first == 2); 71 assert(i->second == "four"); 72 73 eq = c.equal_range(3); 74 assert(std::distance(eq.first, eq.second) == 1); 75 i = eq.first; 76 assert(i->first == 3); 77 assert(i->second == "three"); 78 eq = c.equal_range(4); 79 assert(std::distance(eq.first, eq.second) == 1); 80 i = eq.first; 81 assert(i->first == 4); 82 assert(i->second == "four"); 83 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 84 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 85 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 86 assert(c.max_load_factor() == 1); 87 } 88#if TEST_STD_VER >= 11 89 { 90 typedef min_allocator<std::pair<const int, std::string> > A; 91 typedef std::unordered_multimap<int, std::string, 92 test_hash<std::hash<int> >, 93 test_compare<std::equal_to<int> >, 94 A 95 > C; 96 typedef std::pair<int, std::string> P; 97 C c = { 98 P(4, "four"), 99 P(1, "four"), 100 P(2, "four"), 101 }; 102 c = { 103 P(1, "one"), 104 P(2, "two"), 105 P(3, "three"), 106 P(4, "four"), 107 P(1, "four"), 108 P(2, "four"), 109 }; 110 assert(c.bucket_count() >= 7); 111 assert(c.size() == 6); 112 typedef std::pair<C::const_iterator, C::const_iterator> Eq; 113 Eq eq = c.equal_range(1); 114 assert(std::distance(eq.first, eq.second) == 2); 115 C::const_iterator i = eq.first; 116 assert(i->first == 1); 117 assert(i->second == "one"); 118 ++i; 119 assert(i->first == 1); 120 assert(i->second == "four"); 121 eq = c.equal_range(2); 122 assert(std::distance(eq.first, eq.second) == 2); 123 i = eq.first; 124 assert(i->first == 2); 125 assert(i->second == "two"); 126 ++i; 127 assert(i->first == 2); 128 assert(i->second == "four"); 129 130 eq = c.equal_range(3); 131 assert(std::distance(eq.first, eq.second) == 1); 132 i = eq.first; 133 assert(i->first == 3); 134 assert(i->second == "three"); 135 eq = c.equal_range(4); 136 assert(std::distance(eq.first, eq.second) == 1); 137 i = eq.first; 138 assert(i->first == 4); 139 assert(i->second == "four"); 140 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 141 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 142 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 143 assert(c.max_load_factor() == 1); 144 } 145#endif 146#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 147} 148