fail_ref_cparen.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_ref_cparen.cpp
  12. // Testing const operator() constness.
  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_ref<int,ndims> array_ref;
  22. boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
  23. int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
  24. 14,15,16,17,18,19,20,21,22,23};
  25. array_ref sma(data,sma_dims);
  26. const array_ref& csma = sma;
  27. boost::array<array_ref::index,ndims> indices = {{0,0,0}};
  28. // FAIL! cannot assign to a const multi_array_ref
  29. csma(indices) = 5;
  30. return boost::report_errors();
  31. }