| 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 && !stdlib=libc++ |
| 10 | |
| 11 | // <vector> |
| 12 | |
| 13 | // iterator insert(const_iterator position, value_type&& x); |
| 14 | |
| 15 | #include <vector> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "test_allocator.h" |
| 20 | #include "MoveOnly.h" |
| 21 | #include "min_allocator.h" |
| 22 | #include "asan_testing.h" |
| 23 | |
| 24 | TEST_CONSTEXPR_CXX20 bool tests() { |
| 25 | { |
| 26 | std::vector<MoveOnly> v(100); |
| 27 | std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); |
| 28 | assert(v.size() == 101); |
| 29 | assert(is_contiguous_container_asan_correct(v)); |
| 30 | assert(i == v.begin() + 10); |
| 31 | int j; |
| 32 | for (j = 0; j < 10; ++j) |
| 33 | assert(v[j] == MoveOnly()); |
| 34 | assert(v[j] == MoveOnly(3)); |
| 35 | for (++j; j < 101; ++j) |
| 36 | assert(v[j] == MoveOnly()); |
| 37 | } |
| 38 | { |
| 39 | std::vector<MoveOnly, limited_allocator<MoveOnly, 300> > v(100); |
| 40 | std::vector<MoveOnly, limited_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); |
| 41 | assert(v.size() == 101); |
| 42 | assert(is_contiguous_container_asan_correct(v)); |
| 43 | assert(i == v.begin() + 10); |
| 44 | int j; |
| 45 | for (j = 0; j < 10; ++j) |
| 46 | assert(v[j] == MoveOnly()); |
| 47 | assert(v[j] == MoveOnly(3)); |
| 48 | for (++j; j < 101; ++j) |
| 49 | assert(v[j] == MoveOnly()); |
| 50 | } |
| 51 | { |
| 52 | std::vector<MoveOnly, min_allocator<MoveOnly> > v(100); |
| 53 | std::vector<MoveOnly, min_allocator<MoveOnly> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); |
| 54 | assert(v.size() == 101); |
| 55 | assert(is_contiguous_container_asan_correct(v)); |
| 56 | assert(i == v.begin() + 10); |
| 57 | int j; |
| 58 | for (j = 0; j < 10; ++j) |
| 59 | assert(v[j] == MoveOnly()); |
| 60 | assert(v[j] == MoveOnly(3)); |
| 61 | for (++j; j < 101; ++j) |
| 62 | assert(v[j] == MoveOnly()); |
| 63 | } |
| 64 | { |
| 65 | std::vector<MoveOnly, safe_allocator<MoveOnly> > v(100); |
| 66 | std::vector<MoveOnly, safe_allocator<MoveOnly> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); |
| 67 | assert(v.size() == 101); |
| 68 | assert(is_contiguous_container_asan_correct(v)); |
| 69 | assert(i == v.begin() + 10); |
| 70 | int j; |
| 71 | for (j = 0; j < 10; ++j) |
| 72 | assert(v[j] == MoveOnly()); |
| 73 | assert(v[j] == MoveOnly(3)); |
| 74 | for (++j; j < 101; ++j) |
| 75 | assert(v[j] == MoveOnly()); |
| 76 | } |
| 77 | |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | int main(int, char**) { |
| 82 | tests(); |
| 83 | #if TEST_STD_VER > 17 |
| 84 | static_assert(tests()); |
| 85 | #endif |
| 86 | return 0; |
| 87 | } |
| 88 | |