1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <iterator>
11
12// insert_iterator
13
14// requires CopyConstructible<Cont::value_type>
15//   insert_iterator<Cont>&
16//   operator=(const Cont::value_type& value);
17
18#include <iterator>
19
20#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
21#include <vector>
22#include <memory>
23#include <cassert>
24
25template <class C>
26void
27test(C c1, typename C::difference_type j,
28     typename C::value_type x1, typename C::value_type x2,
29     typename C::value_type x3, const C& c2)
30{
31    std::insert_iterator<C> q(c1, c1.begin() + j);
32    q = std::move(x1);
33    q = std::move(x2);
34    q = std::move(x3);
35    assert(c1 == c2);
36}
37
38template <class C>
39void
40insert3at(C& c, typename C::iterator i,
41     typename C::value_type x1, typename C::value_type x2,
42     typename C::value_type x3)
43{
44    i = c.insert(i, std::move(x1));
45    i = c.insert(++i, std::move(x2));
46    c.insert(++i, std::move(x3));
47}
48
49struct do_nothing
50{
51    void operator()(void*) const {}
52};
53
54#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
55
56int main()
57{
58#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
97}
98