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