Changeset View
Changeset View
Standalone View
Standalone View
test/std/containers/unord/unord.multimap/reserve.pass.cpp
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// The LLVM Compiler Infrastructure | // The LLVM Compiler Infrastructure | ||||
// | // | ||||
// This file is dual licensed under the MIT and the University of Illinois Open | // This file is dual licensed under the MIT and the University of Illinois Open | ||||
// Source Licenses. See LICENSE.TXT for details. | // Source Licenses. See LICENSE.TXT for details. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// <unordered_map> | // <unordered_map> | ||||
// 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 reserve(size_type n); | ||||
#include <unordered_map> | #include <unordered_map> | ||||
#include <string> | #include <string> | ||||
#include <set> | |||||
#include <cassert> | #include <cassert> | ||||
#include "test_macros.h" | #include "test_macros.h" | ||||
#include "min_allocator.h" | #include "min_allocator.h" | ||||
template <class C> | template <class C> | ||||
void test(const C& c) | void test(const C& c) | ||||
{ | { | ||||
assert(c.size() == 6); | assert(c.size() == 6); | ||||
assert(c.find(1)->second == "one"); | { | ||||
assert(next(c.find(1))->second == "four"); | std::set<std::string> s = {"one", "four"}; | ||||
ldionne: This is going to fail in C++03 mode because you're using initializer-list construction. | |||||
assert(c.find(2)->second == "two"); | assert(s.find(c.find(1)->second) != s.end()); | ||||
assert(next(c.find(2))->second == "four"); | s.erase(s.find(c.find(1)->second)); | ||||
assert(s.find(next(c.find(1))->second) != s.end()); | |||||
} | |||||
{ | |||||
std::set<std::string> s = {"two", "four"}; | |||||
assert(s.find(c.find(2)->second) != s.end()); | |||||
s.erase(s.find(c.find(2)->second)); | |||||
assert(s.find(next(c.find(2))->second) != s.end()); | |||||
} | |||||
assert(c.find(3)->second == "three"); | assert(c.find(3)->second == "three"); | ||||
assert(c.find(4)->second == "four"); | assert(c.find(4)->second == "four"); | ||||
} | } | ||||
void reserve_invariant(size_t n) // LWG #2156 | void reserve_invariant(size_t n) // LWG #2156 | ||||
{ | { | ||||
for (size_t i = 0; i < n; ++i) | for (size_t i = 0; i < n; ++i) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
This is going to fail in C++03 mode because you're using initializer-list construction.