lv_value.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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#include <vector>
20#include <cassert>
21
22template <class C>
23void
24test(C c1, typename C::difference_type j,
25     typename C::value_type x1, typename C::value_type x2,
26     typename C::value_type x3, const C& c2)
27{
28    std::insert_iterator<C> q(c1, c1.begin() + j);
29    q = x1;
30    q = x2;
31    q = x3;
32    assert(c1 == c2);
33}
34
35template <class C>
36void
37insert3at(C& c, typename C::iterator i,
38     typename C::value_type x1, typename C::value_type x2,
39     typename C::value_type x3)
40{
41    i = c.insert(i, x1);
42    i = c.insert(++i, x2);
43    c.insert(++i, x3);
44}
45
46int main()
47{
48    typedef std::vector<int> C;
49    C c1;
50    for (int i = 0; i < 3; ++i)
51        c1.push_back(i);
52    C c2 = c1;
53    insert3at(c2, c2.begin(), 'a', 'b', 'c');
54    test(c1, 0, 'a', 'b', 'c', c2);
55    c2 = c1;
56    insert3at(c2, c2.begin()+1, 'a', 'b', 'c');
57    test(c1, 1, 'a', 'b', 'c', c2);
58    c2 = c1;
59    insert3at(c2, c2.begin()+2, 'a', 'b', 'c');
60    test(c1, 2, 'a', 'b', 'c', c2);
61    c2 = c1;
62    insert3at(c2, c2.begin()+3, 'a', 'b', 'c');
63    test(c1, 3, 'a', 'b', 'c', c2);
64}
65