| 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 | // <set> |
| 12 | |
| 13 | // class set |
| 14 | |
| 15 | // template <class... Args> |
| 16 | // iterator emplace_hint(const_iterator position, Args&&... args); |
| 17 | |
| 18 | #include <set> |
| 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::set<DefaultOnly> M; |
| 29 | typedef M::iterator R; |
| 30 | M m; |
| 31 | assert(DefaultOnly::count == 0); |
| 32 | R r = m.emplace_hint(m.cend()); |
| 33 | assert(r == m.begin()); |
| 34 | assert(m.size() == 1); |
| 35 | assert(*m.begin() == DefaultOnly()); |
| 36 | assert(DefaultOnly::count == 1); |
| 37 | |
| 38 | r = m.emplace_hint(m.cbegin()); |
| 39 | assert(r == m.begin()); |
| 40 | assert(m.size() == 1); |
| 41 | assert(*m.begin() == DefaultOnly()); |
| 42 | assert(DefaultOnly::count == 1); |
| 43 | } |
| 44 | assert(DefaultOnly::count == 0); |
| 45 | { |
| 46 | typedef std::set<Emplaceable> M; |
| 47 | typedef M::iterator R; |
| 48 | M m; |
| 49 | R r = m.emplace_hint(m.cend()); |
| 50 | assert(r == m.begin()); |
| 51 | assert(m.size() == 1); |
| 52 | assert(*m.begin() == Emplaceable()); |
| 53 | r = m.emplace_hint(m.cend(), 2, 3.5); |
| 54 | assert(r == std::next(m.begin())); |
| 55 | assert(m.size() == 2); |
| 56 | assert(*r == Emplaceable(2, 3.5)); |
| 57 | r = m.emplace_hint(m.cbegin(), 2, 3.5); |
| 58 | assert(r == std::next(m.begin())); |
| 59 | assert(m.size() == 2); |
| 60 | assert(*r == Emplaceable(2, 3.5)); |
| 61 | } |
| 62 | { |
| 63 | typedef std::set<int> M; |
| 64 | typedef M::iterator R; |
| 65 | M m; |
| 66 | R r = m.emplace_hint(pos: m.cend(), args: M::value_type(2)); |
| 67 | assert(r == m.begin()); |
| 68 | assert(m.size() == 1); |
| 69 | assert(*r == 2); |
| 70 | } |
| 71 | { |
| 72 | typedef std::set<int, std::less<int>, min_allocator<int>> M; |
| 73 | typedef M::iterator R; |
| 74 | M m; |
| 75 | R r = m.emplace_hint(m.cend(), M::value_type(2)); |
| 76 | assert(r == m.begin()); |
| 77 | assert(m.size() == 1); |
| 78 | assert(*r == 2); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |