Changeset View
Changeset View
Standalone View
Standalone View
test/std/containers/unord/unord.multimap/rehash.pass.cpp
Show All 11 Lines | |||||
// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, | ||||
// class Alloc = allocator<pair<const Key, T>>> | // class Alloc = allocator<pair<const Key, T>>> | ||||
// class unordered_multimap | // class unordered_multimap | ||||
// void rehash(size_type n); | // void rehash(size_type n); | ||||
#include <unordered_map> | #include <unordered_map> | ||||
#include <string> | #include <string> | ||||
#include <set> | |||||
#include <cassert> | #include <cassert> | ||||
#include <cfloat> | #include <cfloat> | ||||
#include <cmath> | #include <cmath> | ||||
#include <cstddef> | #include <cstddef> | ||||
#include "test_macros.h" | #include "test_macros.h" | ||||
#include "min_allocator.h" | #include "min_allocator.h" | ||||
template <class C> | template <class C> | ||||
void rehash_postcondition(const C& c, size_t n) | void rehash_postcondition(const C& c, size_t n) | ||||
{ | { | ||||
assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); | assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); | ||||
} | } | ||||
template <class C> | template <class C> | ||||
void test(const C& c) | void test(const C& c) | ||||
{ | { | ||||
assert(c.size() == 6); | assert(c.size() == 6); | ||||
typedef std::pair<typename C::const_iterator, typename C::const_iterator> Eq; | typedef std::pair<typename C::const_iterator, typename C::const_iterator> Eq; | ||||
Eq eq = c.equal_range(1); | Eq eq = c.equal_range(1); | ||||
assert(std::distance(eq.first, eq.second) == 2); | assert(std::distance(eq.first, eq.second) == 2); | ||||
typename C::const_iterator i = eq.first; | typename C::const_iterator i = eq.first; | ||||
{ | |||||
std::set<std::string> s = {"one", "four"}; | |||||
for ( int n = 0; n < 2; ++n ) | |||||
{ | |||||
assert(i->first == 1); | assert(i->first == 1); | ||||
assert(i->second == "one"); | assert(s.find(i->second) != s.end()); | ||||
s.erase(s.find(i->second)); | |||||
++i; | ++i; | ||||
assert(i->first == 1); | } | ||||
assert(i->second == "four"); | } | ||||
eq = c.equal_range(2); | eq = c.equal_range(2); | ||||
assert(std::distance(eq.first, eq.second) == 2); | assert(std::distance(eq.first, eq.second) == 2); | ||||
i = eq.first; | i = eq.first; | ||||
{ | |||||
std::set<std::string> s = {"two", "four"}; | |||||
for ( int n = 0; n < 2; ++n ) | |||||
{ | |||||
assert(i->first == 2); | assert(i->first == 2); | ||||
assert(i->second == "two"); | assert(s.find(i->second) != s.end()); | ||||
s.erase(s.find(i->second)); | |||||
++i; | ++i; | ||||
assert(i->first == 2); | } | ||||
assert(i->second == "four"); | } | ||||
eq = c.equal_range(3); | eq = c.equal_range(3); | ||||
assert(std::distance(eq.first, eq.second) == 1); | assert(std::distance(eq.first, eq.second) == 1); | ||||
i = eq.first; | i = eq.first; | ||||
assert(i->first == 3); | assert(i->first == 3); | ||||
assert(i->second == "three"); | assert(i->second == "three"); | ||||
eq = c.equal_range(4); | eq = c.equal_range(4); | ||||
assert(std::distance(eq.first, eq.second) == 1); | assert(std::distance(eq.first, eq.second) == 1); | ||||
i = eq.first; | i = eq.first; | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |