PageRenderTime 15ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/iterator/doc/reverse_iterator_eg.rst

http://hadesmem.googlecode.com/
ReStructuredText | 45 lines | 31 code | 14 blank | 0 comment | 0 complexity | c8d7ab12d1605fce3c7067a4a301314a MD5 | raw file
 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)
 4
 5Example
 6.......
 7
 8The following example prints an array of characters in reverse order
 9using ``reverse_iterator``.
10
11::
12    
13    char letters_[] = "hello world!";
14    const int N = sizeof(letters_)/sizeof(char) - 1;
15    typedef char* base_iterator;
16    base_iterator letters(letters_);
17    std::cout << "original sequence of letters:\t\t\t" << letters_ << std::endl;
18
19    boost::reverse_iterator<base_iterator>
20      reverse_letters_first(letters + N),
21      reverse_letters_last(letters);
22
23    std::cout << "sequence in reverse order:\t\t\t";
24    std::copy(reverse_letters_first, reverse_letters_last,
25              std::ostream_iterator<char>(std::cout));
26    std::cout << std::endl;
27
28    std::cout << "sequence in double-reversed (normal) order:\t";
29    std::copy(boost::make_reverse_iterator(reverse_letters_last),
30              boost::make_reverse_iterator(reverse_letters_first),
31              std::ostream_iterator<char>(std::cout));
32    std::cout << std::endl;
33
34
35
36The output is::
37
38    original sequence of letters:                   hello world!
39    sequence in reverse order:                      !dlrow olleh
40    sequence in double-reversed (normal) order:     hello world!
41
42
43The source code for this example can be found `here`__.
44
45__ ../example/reverse_iterator_example.cpp