1 .. Copyright David Abrahams 2006. Distributed under the Boost
2 .. Software License, Version 1.0. (See accompanying
3 .. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 This example fills an array with numbers and a second array with
9 pointers into the first array, using ``counting_iterator`` for both
10 tasks. Finally ``indirect_iterator`` is used to print out the numbers
11 into the first array via indirection through the second array.
16 std::vector<int> numbers;
17 typedef std::vector<int>::iterator n_iter;
18 std::copy(boost::counting_iterator<int>(0),
19 boost::counting_iterator<int>(N),
20 std::back_inserter(numbers));
22 std::vector<std::vector<int>::iterator> pointers;
23 std::copy(boost::make_counting_iterator(numbers.begin()),
24 boost::make_counting_iterator(numbers.end()),
25 std::back_inserter(pointers));
27 std::cout << "indirectly printing out the numbers from 0 to "
29 std::copy(boost::make_indirect_iterator(pointers.begin()),
30 boost::make_indirect_iterator(pointers.end()),
31 std::ostream_iterator<int>(std::cout, " "));
32 std::cout << std::endl;
37 indirectly printing out the numbers from 0 to 7
40 The source code for this example can be found `here`__.
42 __ ../example/counting_iterator_example.cpp