| 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 | // <map> |
| 12 | |
| 13 | // class map |
| 14 | |
| 15 | // template <class... Args> |
| 16 | // iterator emplace_hint(const_iterator position, Args&&... args); |
| 17 | |
| 18 | #include <map> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | #include "../../../Emplaceable.h" |
| 23 | #include "DefaultOnly.h" |
| 24 | #include "min_allocator.h" |
| 25 | |
| 26 | int main(int, char**) { |
| 27 | { |
| 28 | typedef std::map<int, DefaultOnly> M; |
| 29 | typedef M::iterator R; |
| 30 | M m; |
| 31 | assert(DefaultOnly::count == 0); |
| 32 | R r = m.emplace_hint(m.end()); |
| 33 | assert(r == m.begin()); |
| 34 | assert(m.size() == 1); |
| 35 | assert(m.begin()->first == 0); |
| 36 | assert(m.begin()->second == DefaultOnly()); |
| 37 | assert(DefaultOnly::count == 1); |
| 38 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple()); |
| 39 | assert(r == std::next(m.begin())); |
| 40 | assert(m.size() == 2); |
| 41 | assert(std::next(m.begin())->first == 1); |
| 42 | assert(std::next(m.begin())->second == DefaultOnly()); |
| 43 | assert(DefaultOnly::count == 2); |
| 44 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple()); |
| 45 | assert(r == std::next(m.begin())); |
| 46 | assert(m.size() == 2); |
| 47 | assert(std::next(m.begin())->first == 1); |
| 48 | assert(std::next(m.begin())->second == DefaultOnly()); |
| 49 | assert(DefaultOnly::count == 2); |
| 50 | } |
| 51 | assert(DefaultOnly::count == 0); |
| 52 | { |
| 53 | typedef std::map<int, Emplaceable> M; |
| 54 | typedef M::iterator R; |
| 55 | M m; |
| 56 | R r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 2), std::forward_as_tuple()); |
| 57 | assert(r == m.begin()); |
| 58 | assert(m.size() == 1); |
| 59 | assert(m.begin()->first == 2); |
| 60 | assert(m.begin()->second == Emplaceable()); |
| 61 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple(args: 2, args: 3.5)); |
| 62 | assert(r == m.begin()); |
| 63 | assert(m.size() == 2); |
| 64 | assert(m.begin()->first == 1); |
| 65 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 66 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple(args: 2, args: 3.5)); |
| 67 | assert(r == m.begin()); |
| 68 | assert(m.size() == 2); |
| 69 | assert(m.begin()->first == 1); |
| 70 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 71 | } |
| 72 | { |
| 73 | typedef std::map<int, double> M; |
| 74 | typedef M::iterator R; |
| 75 | M m; |
| 76 | R r = m.emplace_hint(pos: m.end(), args: M::value_type(2, 3.5)); |
| 77 | assert(r == m.begin()); |
| 78 | assert(m.size() == 1); |
| 79 | assert(m.begin()->first == 2); |
| 80 | assert(m.begin()->second == 3.5); |
| 81 | } |
| 82 | { |
| 83 | typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M; |
| 84 | typedef M::iterator R; |
| 85 | M m; |
| 86 | assert(DefaultOnly::count == 0); |
| 87 | R r = m.emplace_hint(m.end()); |
| 88 | assert(r == m.begin()); |
| 89 | assert(m.size() == 1); |
| 90 | assert(m.begin()->first == 0); |
| 91 | assert(m.begin()->second == DefaultOnly()); |
| 92 | assert(DefaultOnly::count == 1); |
| 93 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple()); |
| 94 | assert(r == std::next(m.begin())); |
| 95 | assert(m.size() == 2); |
| 96 | assert(std::next(m.begin())->first == 1); |
| 97 | assert(std::next(m.begin())->second == DefaultOnly()); |
| 98 | assert(DefaultOnly::count == 2); |
| 99 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple()); |
| 100 | assert(r == std::next(m.begin())); |
| 101 | assert(m.size() == 2); |
| 102 | assert(std::next(m.begin())->first == 1); |
| 103 | assert(std::next(m.begin())->second == DefaultOnly()); |
| 104 | assert(DefaultOnly::count == 2); |
| 105 | } |
| 106 | assert(DefaultOnly::count == 0); |
| 107 | { |
| 108 | typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; |
| 109 | typedef M::iterator R; |
| 110 | M m; |
| 111 | R r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 2), std::forward_as_tuple()); |
| 112 | assert(r == m.begin()); |
| 113 | assert(m.size() == 1); |
| 114 | assert(m.begin()->first == 2); |
| 115 | assert(m.begin()->second == Emplaceable()); |
| 116 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple(args: 2, args: 3.5)); |
| 117 | assert(r == m.begin()); |
| 118 | assert(m.size() == 2); |
| 119 | assert(m.begin()->first == 1); |
| 120 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 121 | r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(args: 1), std::forward_as_tuple(args: 2, args: 3.5)); |
| 122 | assert(r == m.begin()); |
| 123 | assert(m.size() == 2); |
| 124 | assert(m.begin()->first == 1); |
| 125 | assert(m.begin()->second == Emplaceable(2, 3.5)); |
| 126 | } |
| 127 | { |
| 128 | typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; |
| 129 | typedef M::iterator R; |
| 130 | M m; |
| 131 | R r = m.emplace_hint(m.end(), M::value_type(2, 3.5)); |
| 132 | assert(r == m.begin()); |
| 133 | assert(m.size() == 1); |
| 134 | assert(m.begin()->first == 2); |
| 135 | assert(m.begin()->second == 3.5); |
| 136 | } |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |