| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <unordered_map> |
| 12 | |
| 13 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 14 | // class Alloc = allocator<pair<const Key, T>>> |
| 15 | // class unordered_multimap |
| 16 | |
| 17 | // template <class... Args> |
| 18 | // iterator emplace_hint(const_iterator p, Args&&... args); |
| 19 | |
| 20 | #include <unordered_map> |
| 21 | #include <cassert> |
| 22 | #include <iterator> |
| 23 | |
| 24 | #include "../../../Emplaceable.h" |
| 25 | #include "min_allocator.h" |
| 26 | #include "test_macros.h" |
| 27 | |
| 28 | int main(int, char**) { |
| 29 | { |
| 30 | typedef std::unordered_multimap<int, Emplaceable> C; |
| 31 | typedef C::iterator R; |
| 32 | C c; |
| 33 | C::const_iterator e = c.end(); |
| 34 | R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(args: 3), 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(c.end(), 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 | LIBCPP_ASSERT(r == std::next(c.begin())); |
| 44 | |
| 45 | r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(args: 3), std::forward_as_tuple(args: 6, args: 7)); |
| 46 | assert(c.size() == 3); |
| 47 | assert(r->first == 3); |
| 48 | assert(r->second == Emplaceable(6, 7)); |
| 49 | LIBCPP_ASSERT(r == std::next(c.begin())); |
| 50 | r = c.begin(); |
| 51 | assert(r->first == 3); |
| 52 | LIBCPP_ASSERT(r->second == Emplaceable()); |
| 53 | r = std::next(r, 2); |
| 54 | assert(r->first == 3); |
| 55 | LIBCPP_ASSERT(r->second == Emplaceable(5, 6)); |
| 56 | } |
| 57 | { |
| 58 | typedef std::unordered_multimap<int, |
| 59 | Emplaceable, |
| 60 | std::hash<int>, |
| 61 | std::equal_to<int>, |
| 62 | min_allocator<std::pair<const int, Emplaceable>>> |
| 63 | C; |
| 64 | typedef C::iterator R; |
| 65 | C c; |
| 66 | C::const_iterator e = c.end(); |
| 67 | R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(args: 3), std::forward_as_tuple()); |
| 68 | assert(c.size() == 1); |
| 69 | assert(r->first == 3); |
| 70 | assert(r->second == Emplaceable()); |
| 71 | |
| 72 | r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(3, Emplaceable(5, 6))); |
| 73 | assert(c.size() == 2); |
| 74 | assert(r->first == 3); |
| 75 | assert(r->second == Emplaceable(5, 6)); |
| 76 | LIBCPP_ASSERT(r == std::next(c.begin())); |
| 77 | |
| 78 | r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(args: 3), std::forward_as_tuple(args: 6, args: 7)); |
| 79 | assert(c.size() == 3); |
| 80 | assert(r->first == 3); |
| 81 | assert(r->second == Emplaceable(6, 7)); |
| 82 | LIBCPP_ASSERT(r == std::next(c.begin())); |
| 83 | r = c.begin(); |
| 84 | assert(r->first == 3); |
| 85 | LIBCPP_ASSERT(r->second == Emplaceable()); |
| 86 | r = std::next(r, 2); |
| 87 | assert(r->first == 3); |
| 88 | LIBCPP_ASSERT(r->second == Emplaceable(5, 6)); |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |