idxgen1.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // idxset1.cpp - testing the code for index_gen
  12. //
  13. #include <boost/multi_array/index_gen.hpp>
  14. #include <boost/multi_array/index_range.hpp>
  15. #include <boost/multi_array/types.hpp>
  16. #include <boost/core/lightweight_test.hpp>
  17. #include <boost/array.hpp>
  18. typedef boost::detail::multi_array::index index_type;
  19. typedef boost::detail::multi_array::size_type size_type;
  20. typedef boost::detail::multi_array::index_range<index_type,size_type> range;
  21. template <int NumRanges, int NumDims>
  22. void check(const boost::detail::multi_array::
  23. index_gen<NumRanges,NumDims>&) { }
  24. bool operator==(const range& lhs,const range& rhs) {
  25. return lhs.start_ == rhs.start_ &&
  26. lhs.finish_ == rhs.finish_ &&
  27. lhs.stride_ == rhs.stride_ &&
  28. lhs.degenerate_ == rhs.degenerate_;
  29. }
  30. int
  31. main()
  32. {
  33. boost::detail::multi_array::index_gen<0,0> indices;
  34. check<1,1>(indices[range()]);
  35. check<2,2>(indices[range()][range()]);
  36. check<3,3>(indices[range()][range()][range()]);
  37. check<1,0>(indices[0]);
  38. check<2,0>(indices[0][0]);
  39. check<2,1>(indices[range()][0]);
  40. check<2,1>(indices[0][range()]);
  41. check<3,0>(indices[0][0][0]);
  42. check<3,1>(indices[range()][0][0]);
  43. check<3,1>(indices[0][range()][0]);
  44. check<3,1>(indices[0][0][range()]);
  45. check<3,2>(indices[range()][range()][0]);
  46. check<3,2>(indices[range()][0][range()]);
  47. check<3,2>(indices[0][range()][range()]);
  48. {
  49. boost::detail::multi_array::index_gen<3,3> is1 =
  50. indices[range(0,1,2)][range(1,2,3)][range(2,3,4)];
  51. BOOST_TEST(is1.ranges_[0] == range(0,1,2));
  52. BOOST_TEST(is1.ranges_[1] == range(1,2,3));
  53. BOOST_TEST(is1.ranges_[2] == range(2,3,4));
  54. }
  55. {
  56. boost::detail::multi_array::index_gen<3,2> is2 =
  57. indices[range(0,1,2)][2][range(2,3,4)];
  58. BOOST_TEST(is2.ranges_[0] == range(0,1,2));
  59. BOOST_TEST(is2.ranges_[1] == range(2));
  60. BOOST_TEST(is2.ranges_[1].is_degenerate());
  61. BOOST_TEST(is2.ranges_[2] == range(2,3,4));
  62. }
  63. return boost::report_errors();
  64. }