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
| #include <iterator> #include <iostream> #include <list> using namespace std; template <typename T> void printContainer(const list<T>& lists) { for (auto iter = begin(lists); iter != end(lists); ++iter) cout << *iter; cout << endl; } template <typename T> insert_iterator<T> make_insert_iterater(T& lists, typename T::iterator iter) { return insert_iterator<T>(lists, iter); } int main() { int array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; list<int> integers; copy(array + 5, array + 10, back_inserter(integers)); printContainer(integers); using backword_iterator = reverse_iterator < int * >; copy(backword_iterator(array + 5), backword_iterator(array), front_inserter(integers)); printContainer(integers); list<int>::iterator iter = integers.begin(); iter++; iter++; copy(array + 1, array + 3, make_insert_iterater(integers, iter)); printContainer(integers); }
|