1 /* example for using class array<>
2 * (C) Copyright Nicolai M. Josuttis 2001.
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/array.hpp>
13 void print_elements (const T
& x
);
17 // create array of four seasons
18 boost::array
<std::string
,4> seasons
= {
19 { "spring", "summer", "autumn", "winter" }
22 // copy and change order
23 boost::array
<std::string
,4> seasons_orig
= seasons
;
24 for (unsigned i
=seasons
.size()-1; i
>0; --i
) {
25 std::swap(seasons
.at(i
),seasons
.at((i
+1)%seasons
.size()));
28 std::cout
<< "one way: ";
29 print_elements(seasons
);
32 std::cout
<< "other way: ";
33 std::swap(seasons
,seasons_orig
);
34 print_elements(seasons
);
36 // try reverse iterators
37 std::cout
<< "reverse: ";
38 for (boost::array
<std::string
,4>::reverse_iterator pos
39 =seasons
.rbegin(); pos
<seasons
.rend(); ++pos
) {
40 std::cout
<< " " << *pos
;
42 std::cout
<< std::endl
;
44 return 0; // makes Visual-C++ compiler happy
48 void print_elements (const T
& x
)
50 for (unsigned i
=0; i
<x
.size(); ++i
) {
51 std::cout
<< " " << x
[i
];
53 std::cout
<< std::endl
;