| 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 | // iterator insert(const_iterator position, value_type&& v); |
| 16 | |
| 17 | #include <set> |
| 18 | #include <cassert> |
| 19 | #include <iterator> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | #include "MoveOnly.h" |
| 23 | #include "min_allocator.h" |
| 24 | |
| 25 | int main(int, char**) { |
| 26 | { |
| 27 | typedef std::set<MoveOnly> M; |
| 28 | typedef M::iterator R; |
| 29 | M m; |
| 30 | R r = m.insert(m.cend(), M::value_type(2)); |
| 31 | assert(r == m.begin()); |
| 32 | assert(m.size() == 1); |
| 33 | assert(*r == 2); |
| 34 | |
| 35 | r = m.insert(m.cend(), M::value_type(1)); |
| 36 | assert(r == m.begin()); |
| 37 | assert(m.size() == 2); |
| 38 | assert(*r == 1); |
| 39 | |
| 40 | r = m.insert(m.cend(), M::value_type(3)); |
| 41 | assert(r == std::prev(m.end())); |
| 42 | assert(m.size() == 3); |
| 43 | assert(*r == 3); |
| 44 | |
| 45 | r = m.insert(m.cend(), M::value_type(3)); |
| 46 | assert(r == std::prev(m.end())); |
| 47 | assert(m.size() == 3); |
| 48 | assert(*r == 3); |
| 49 | } |
| 50 | { |
| 51 | typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M; |
| 52 | typedef M::iterator R; |
| 53 | M m; |
| 54 | R r = m.insert(m.cend(), M::value_type(2)); |
| 55 | assert(r == m.begin()); |
| 56 | assert(m.size() == 1); |
| 57 | assert(*r == 2); |
| 58 | |
| 59 | r = m.insert(m.cend(), M::value_type(1)); |
| 60 | assert(r == m.begin()); |
| 61 | assert(m.size() == 2); |
| 62 | assert(*r == 1); |
| 63 | |
| 64 | r = m.insert(m.cend(), M::value_type(3)); |
| 65 | assert(r == std::prev(m.end())); |
| 66 | assert(m.size() == 3); |
| 67 | assert(*r == 3); |
| 68 | |
| 69 | r = m.insert(m.cend(), M::value_type(3)); |
| 70 | assert(r == std::prev(m.end())); |
| 71 | assert(m.size() == 3); |
| 72 | assert(*r == 3); |
| 73 | } |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |