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#ifndef _SCL_SECURE_NO_WARNINGS
9// Suppress warnings from the std lib:
10# define _SCL_SECURE_NO_WARNINGS
11#endif
12
13#include <algorithm>
14#include <functional>
15#include <boost/array.hpp>
16#include "print.hpp"
17using namespace std;
18
19int main()
20{
21 // create and initialize array
22 boost::array<int,10> a = { .elems: { 1, 2, 3, 4, 5 } };
23
24 print_elements(coll: a);
25
26 // modify elements directly
27 for (unsigned i=0; i<a.size(); ++i) {
28 ++a[i];
29 }
30 print_elements(coll: a);
31
32 // change order using an STL algorithm
33 reverse(first: a.begin(),last: a.end());
34 print_elements(coll: a);
35
36 // negate elements using STL framework
37 transform(first: a.begin(),last: a.end(), // source
38 result: a.begin(), // destination
39 unary_op: negate<int>()); // operation
40 print_elements(coll: a);
41
42 return 0; // makes Visual-C++ compiler happy
43}
44
45

source code of boost/libs/array/test/array2.cpp