1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <iterator>
// insert_iterator
// requires CopyConstructible<Cont::value_type>
// insert_iterator<Cont>&
// operator=(const Cont::value_type& value);
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
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)
{
std::insert_iterator<C> q(c1, c1.begin() + j);
q = x1;
q = x2;
q = x3;
assert(c1 == c2);
}
template <class C>
void
insert3at(C& c, typename C::iterator i,
typename C::value_type x1, typename C::value_type x2,
typename C::value_type x3)
{
i = c.insert(i, x1);
i = c.insert(++i, x2);
c.insert(++i, x3);
}
int main()
{
{
typedef std::vector<int> C;
C c1;
for (int i = 0; i < 3; ++i)
c1.push_back(i);
C c2 = c1;
insert3at(c2, c2.begin(), 'a', 'b', 'c');
test(c1, 0, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+1, 'a', 'b', 'c');
test(c1, 1, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+2, 'a', 'b', 'c');
test(c1, 2, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+3, 'a', 'b', 'c');
test(c1, 3, 'a', 'b', 'c', c2);
}
{
typedef nasty_vector<int> C;
C c1;
for (int i = 0; i < 3; ++i)
c1.push_back(i);
C c2 = c1;
insert3at(c2, c2.begin(), 'a', 'b', 'c');
test(c1, 0, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+1, 'a', 'b', 'c');
test(c1, 1, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+2, 'a', 'b', 'c');
test(c1, 2, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+3, 'a', 'b', 'c');
test(c1, 3, 'a', 'b', 'c', c2);
}
}
|