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