Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/array/array3.cpp @ 45

Last change on this file since 45 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.3 KB
Line 
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 */
7
8#include <string>
9#include <iostream>
10#include <boost/array.hpp>
11
12template <class T>
13void print_elements (const T& x);
14
15int main()
16{
17    // create array of four seasons
18    boost::array<std::string,4> seasons = {
19        { "spring", "summer", "autumn", "winter" }
20    };
21
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()));
26    }
27
28    std::cout << "one way:   ";
29    print_elements(seasons);
30
31    // try swap()
32    std::cout << "other way: ";
33    std::swap(seasons,seasons_orig);
34    print_elements(seasons);
35
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;
41    }
42    std::cout << std::endl;
43
44    return 0;  // makes Visual-C++ compiler happy
45}
46
47template <class T>
48void print_elements (const T& x)
49{
50    for (unsigned i=0; i<x.size(); ++i) {
51        std::cout << " " << x[i];
52    }
53    std::cout << std::endl;
54}
55
Note: See TracBrowser for help on using the repository browser.