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