fail_csubarray3.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // fail_csubarray3.cpp
  12. // Testing constness of subarray operations.
  13. //
  14. #include <boost/multi_array.hpp>
  15. #include <boost/core/lightweight_test.hpp>
  16. #include <boost/array.hpp>
  17. int
  18. main()
  19. {
  20. const int ndims=3;
  21. typedef boost::multi_array<int,ndims> array;
  22. boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
  23. array sma(sma_dims);
  24. int num = 0;
  25. for (array::index i = 0; i != 2; ++i)
  26. for (array::index j = 0; j != 3; ++j)
  27. for (array::index k = 0; k != 4; ++k)
  28. sma[i][j][k] = num++;
  29. const array& sma_const = sma;
  30. array::const_subarray<ndims-1>::type sba = sma_const[0];
  31. for (array::index j = 0; j != 3; ++j)
  32. for (array::index k = 0; k != 4; ++k)
  33. // FAIL! sba cannot be assigned to.
  34. sba[j][k] = num++;
  35. return boost::report_errors();
  36. }