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// <iterator>
12
13// insert_iterator
14
15// requires CopyConstructible<Cont::value_type>
16// insert_iterator<Cont>&
17// operator=(const Cont::value_type& value);
18
19#include <iterator>
20
21#include <utility>
22#include <vector>
23#include <memory>
24#include <cassert>
25
26#include "test_macros.h"
27
28template <class C>
29void
30test(C c1, typename C::difference_type j,
31 typename C::value_type x1, typename C::value_type x2,
32 typename C::value_type x3, const C& c2)
33{
34 std::insert_iterator<C> q(c1, c1.begin() + j);
35 q = std::move(x1);
36 q = std::move(x2);
37 q = std::move(x3);
38 assert(c1 == c2);
39}
40
41template <class C>
42void
43insert3at(C& c, typename C::iterator i,
44 typename C::value_type x1, typename C::value_type x2,
45 typename C::value_type x3)
46{
47 i = c.insert(i, std::move(x1));
48 i = c.insert(++i, std::move(x2));
49 c.insert(++i, std::move(x3));
50}
51
52struct do_nothing
53{
54 void operator()(void*) const {}
55};
56
57int main(int, char**)
58{
59 {
60 typedef std::unique_ptr<int, do_nothing> Ptr;
61 typedef std::vector<Ptr> C;
62 C c1;
63 int x[6] = {0};
64 for (int i = 0; i < 3; ++i)
65 c1.push_back(Ptr(x+i));
66 C c2;
67 for (int i = 0; i < 3; ++i)
68 c2.push_back(Ptr(x+i));
69 insert3at(c2, c2.begin(), Ptr(x+3), Ptr(x+4), Ptr(x+5));
70 test(std::move(c1), 0, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
71 c1.clear();
72 for (int i = 0; i < 3; ++i)
73 c1.push_back(Ptr(x+i));
74 c2.clear();
75 for (int i = 0; i < 3; ++i)
76 c2.push_back(Ptr(x+i));
77 insert3at(c2, c2.begin()+1, Ptr(x+3), Ptr(x+4), Ptr(x+5));
78 test(std::move(c1), 1, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
79 c1.clear();
80 for (int i = 0; i < 3; ++i)
81 c1.push_back(Ptr(x+i));
82 c2.clear();
83 for (int i = 0; i < 3; ++i)
84 c2.push_back(Ptr(x+i));
85 insert3at(c2, c2.begin()+2, Ptr(x+3), Ptr(x+4), Ptr(x+5));
86 test(std::move(c1), 2, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
87 c1.clear();
88 for (int i = 0; i < 3; ++i)
89 c1.push_back(Ptr(x+i));
90 c2.clear();
91 for (int i = 0; i < 3; ++i)
92 c2.push_back(Ptr(x+i));
93 insert3at(c2, c2.begin()+3, Ptr(x+3), Ptr(x+4), Ptr(x+5));
94 test(std::move(c1), 3, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
95 }
96
97 return 0;
98}
99

source code of libcxx/test/std/iterators/predef.iterators/insert.iterators/insert.iter.ops/insert.iter.op=/rv_value.pass.cpp