emplace_hint.pass.cpp revision ad46d2248426e810edc5878c7cb086b7093f3cf5
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// template <class... Args> 17// iterator emplace_hint(const_iterator p, Args&&... args); 18 19#include <unordered_map> 20#include <cassert> 21 22#include "../../../Emplaceable.h" 23#include "../../../min_allocator.h" 24 25int main() 26{ 27#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 28 { 29 typedef std::unordered_multimap<int, Emplaceable> C; 30 typedef C::iterator R; 31 C c; 32 C::const_iterator e = c.end(); 33 R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3), 34 std::forward_as_tuple()); 35 assert(c.size() == 1); 36 assert(r->first == 3); 37 assert(r->second == Emplaceable()); 38 39 r = c.emplace_hint(e, std::pair<const int, Emplaceable>(3, Emplaceable(5, 6))); 40 assert(c.size() == 2); 41 assert(r->first == 3); 42 assert(r->second == Emplaceable(5, 6)); 43 assert(r == next(c.begin())); 44 45 r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3), 46 std::forward_as_tuple(6, 7)); 47 assert(c.size() == 3); 48 assert(r->first == 3); 49 assert(r->second == Emplaceable(6, 7)); 50 assert(r == next(c.begin())); 51 r = c.begin(); 52 assert(r->first == 3); 53 assert(r->second == Emplaceable()); 54 r = next(r, 2); 55 assert(r->first == 3); 56 assert(r->second == Emplaceable(5, 6)); 57 } 58#if __cplusplus >= 201103L 59 { 60 typedef std::unordered_multimap<int, Emplaceable, std::hash<int>, std::equal_to<int>, 61 min_allocator<std::pair<const int, Emplaceable>>> C; 62 typedef C::iterator R; 63 C c; 64 C::const_iterator e = c.end(); 65 R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3), 66 std::forward_as_tuple()); 67 assert(c.size() == 1); 68 assert(r->first == 3); 69 assert(r->second == Emplaceable()); 70 71 r = c.emplace_hint(e, std::pair<const int, Emplaceable>(3, Emplaceable(5, 6))); 72 assert(c.size() == 2); 73 assert(r->first == 3); 74 assert(r->second == Emplaceable(5, 6)); 75 assert(r == next(c.begin())); 76 77 r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3), 78 std::forward_as_tuple(6, 7)); 79 assert(c.size() == 3); 80 assert(r->first == 3); 81 assert(r->second == Emplaceable(6, 7)); 82 assert(r == next(c.begin())); 83 r = c.begin(); 84 assert(r->first == 3); 85 assert(r->second == Emplaceable()); 86 r = next(r, 2); 87 assert(r->first == 3); 88 assert(r->second == Emplaceable(5, 6)); 89 } 90#endif 91#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 92} 93