reverse_view.cpp 1.1 KB

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