Rev | Line | |
---|
[12] | 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 <algorithm> |
---|
| 9 | #include <functional> |
---|
| 10 | #include <boost/array.hpp> |
---|
| 11 | #include "print.hpp" |
---|
| 12 | using namespace std; |
---|
| 13 | using namespace boost; |
---|
| 14 | |
---|
| 15 | int main() |
---|
| 16 | { |
---|
| 17 | // create and initialize array |
---|
| 18 | array<int,10> a = { { 1, 2, 3, 4, 5 } }; |
---|
| 19 | |
---|
| 20 | print_elements(a); |
---|
| 21 | |
---|
| 22 | // modify elements directly |
---|
| 23 | for (unsigned i=0; i<a.size(); ++i) { |
---|
| 24 | ++a[i]; |
---|
| 25 | } |
---|
| 26 | print_elements(a); |
---|
| 27 | |
---|
| 28 | // change order using an STL algorithm |
---|
| 29 | reverse(a.begin(),a.end()); |
---|
| 30 | print_elements(a); |
---|
| 31 | |
---|
| 32 | // negate elements using STL framework |
---|
| 33 | transform(a.begin(),a.end(), // source |
---|
| 34 | a.begin(), // destination |
---|
| 35 | negate<int>()); // operation |
---|
| 36 | print_elements(a); |
---|
| 37 | |
---|
| 38 | return 0; // makes Visual-C++ compiler happy |
---|
| 39 | } |
---|
| 40 | |
---|
Note: See
TracBrowser
for help on using the repository browser.