Improve vacpp support.
[boost.git] / boost / libs / array / array3.cpp
bloba4eac5d8800abf4e444a1afc47279a061c6b9830
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)
6 */
8 #include <string>
9 #include <iostream>
10 #include <boost/array.hpp>
12 template <class T>
13 void print_elements (const T& x);
15 int main()
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);
31 // try swap()
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
47 template <class T>
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;