| 1 | #include <boost/multi_array.hpp>
|
|---|
| 2 | #include <boost/multi_array/index_range.hpp>
|
|---|
| 3 | #include <boost/detail/lightweight_test.hpp>
|
|---|
| 4 |
|
|---|
| 5 | #ifdef DEBUG_OUTPUT
|
|---|
| 6 | #include <iostream>
|
|---|
| 7 | #endif
|
|---|
| 8 |
|
|---|
| 9 | int
|
|---|
| 10 | main()
|
|---|
| 11 | {
|
|---|
| 12 | typedef boost::multi_array<size_t, 1> MA;
|
|---|
| 13 |
|
|---|
| 14 | MA ma(boost::extents[8]);
|
|---|
| 15 |
|
|---|
| 16 | for (size_t i = 0; i < 4; ++i)
|
|---|
| 17 | {
|
|---|
| 18 | ma[i] = i;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | MA::const_array_view<1>::type src =
|
|---|
| 22 | ma[boost::indices[MA::index_range(0,4)]];
|
|---|
| 23 |
|
|---|
| 24 | #ifdef FUDGED_RANGE
|
|---|
| 25 | // This is wrong, but works.
|
|---|
| 26 | MA::array_view<1>::type dst =
|
|---|
| 27 | ma[boost::indices[MA::index_range(7,5,-1)]];
|
|---|
| 28 | #else
|
|---|
| 29 | // This is correct, but fails.
|
|---|
| 30 | MA::array_view<1>::type dst =
|
|---|
| 31 | ma[boost::indices[MA::index_range(7,3,-1)]];
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | #ifdef DEBUG_OUTPUT
|
|---|
| 35 | std::cout << "src.shape()[0] = " << src.shape()[0] << std::endl;
|
|---|
| 36 | std::cout << "dst.shape()[0] = " << dst.shape()[0] << std::endl;
|
|---|
| 37 | #endif
|
|---|
| 38 |
|
|---|
| 39 | BOOST_TEST(src.shape()[0] == dst.shape()[0]);
|
|---|
| 40 |
|
|---|
| 41 | dst = src;
|
|---|
| 42 |
|
|---|
| 43 | for (size_t i = 0; i < 4; ++i)
|
|---|
| 44 | {
|
|---|
| 45 | BOOST_TEST(ma[i] == i);
|
|---|
| 46 | BOOST_TEST(ma[i] == ma[7 - i]);
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | return boost::report_errors();
|
|---|
| 50 | }
|
|---|