| 1 | // Copyright 2002 The Trustees of Indiana University. |
| 2 | |
| 3 | // Use, modification and distribution is subject to the Boost Software |
| 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | // http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | // Boost.MultiArray Library |
| 8 | // Authors: Ronald Garcia |
| 9 | // Jeremy Siek |
| 10 | // Andrew Lumsdaine |
| 11 | // See http://www.boost.org/libs/multi_array for documentation. |
| 12 | |
| 13 | // |
| 14 | // reverse_view.cpp - a small test of creating a view with negative strides |
| 15 | // |
| 16 | |
| 17 | #include <boost/multi_array.hpp> |
| 18 | #include <boost/core/lightweight_test.hpp> |
| 19 | #include <boost/array.hpp> |
| 20 | |
| 21 | int |
| 22 | main() |
| 23 | { |
| 24 | using namespace boost; |
| 25 | |
| 26 | |
| 27 | // One-dimensional array with views |
| 28 | double data[] = { 1, 2, 3, 4 }; |
| 29 | double rdata[] = { 4, 3, 2, 1 }; |
| 30 | |
| 31 | typedef multi_array< double, 1 > array; |
| 32 | array A(extents[4]); |
| 33 | A.assign(begin: data,end: data+4); |
| 34 | |
| 35 | typedef array::index_range range; |
| 36 | array::array_view<1>::type B = A[indices[range(3, -1, -1)]]; |
| 37 | |
| 38 | for(multi_array_types::size_type i = 0; i != B.size(); ++i) { |
| 39 | BOOST_TEST(B[i] == rdata[i]); |
| 40 | } |
| 41 | |
| 42 | return boost::report_errors(); |
| 43 | } |
| 44 | |