1 // (C) Copyright Jeremy Siek 2000-2004. 2 // Distributed under the Boost Software License, Version 1.0. (See 3 // accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 #include <boost/config.hpp> 7 #include <iostream> 8 #include <algorithm> 9 #include <boost/iterator/reverse_iterator.hpp> 10 #include <boost/cstdlib.hpp> 11 main(int,char * [])12int main(int, char*[]) 13 { 14 char letters_[] = "hello world!"; 15 const int N = sizeof(letters_)/sizeof(char) - 1; 16 typedef char* base_iterator; 17 base_iterator letters(letters_); 18 19 std::cout << "original sequence of letters:\t\t\t" 20 << letters_ << std::endl; 21 22 // Use reverse_iterator to print a sequence of letters in reverse 23 // order. 24 25 boost::reverse_iterator<base_iterator> 26 reverse_letters_first(letters + N), 27 reverse_letters_last(letters); 28 29 std::cout << "sequence in reverse order:\t\t\t"; 30 std::copy(reverse_letters_first, reverse_letters_last, 31 std::ostream_iterator<char>(std::cout)); 32 std::cout << std::endl; 33 34 std::cout << "sequence in double-reversed (normal) order:\t"; 35 std::copy(boost::make_reverse_iterator(reverse_letters_last), 36 boost::make_reverse_iterator(reverse_letters_first), 37 std::ostream_iterator<char>(std::cout)); 38 std::cout << std::endl; 39 40 return boost::exit_success; 41 } 42