1 | // Copyright 2002 The Trustees of Indiana University. |
2 | |
3 | // Use, modification and distribution is subject to the Boost Software |
4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
5 | // http://www.boost.org/LICENSE_1_0.txt) |
6 | |
7 | // Boost.MultiArray Library |
8 | // Authors: Ronald Garcia |
9 | // Jeremy Siek |
10 | // Andrew Lumsdaine |
11 | // See http://www.boost.org/libs/multi_array for documentation. |
12 | |
13 | // |
14 | // idxset1.cpp - testing the code for index_gen |
15 | // |
16 | |
17 | #include <boost/multi_array/index_gen.hpp> |
18 | #include <boost/multi_array/index_range.hpp> |
19 | #include <boost/multi_array/types.hpp> |
20 | #include <boost/core/lightweight_test.hpp> |
21 | |
22 | #include <boost/array.hpp> |
23 | |
24 | typedef boost::detail::multi_array::index index_type; |
25 | typedef boost::detail::multi_array::size_type size_type; |
26 | typedef boost::detail::multi_array::index_range<index_type,size_type> range; |
27 | |
28 | template <int NumRanges, int NumDims> |
29 | void check(const boost::detail::multi_array:: |
30 | index_gen<NumRanges,NumDims>&) { } |
31 | |
32 | bool operator==(const range& lhs,const range& rhs) { |
33 | return lhs.start_ == rhs.start_ && |
34 | lhs.finish_ == rhs.finish_ && |
35 | lhs.stride_ == rhs.stride_ && |
36 | lhs.degenerate_ == rhs.degenerate_; |
37 | } |
38 | |
39 | int |
40 | main() |
41 | { |
42 | |
43 | boost::detail::multi_array::index_gen<0,0> indices; |
44 | |
45 | |
46 | check<1,1>(indices[range()]); |
47 | check<2,2>(indices[range()][range()]); |
48 | check<3,3>(indices[range()][range()][range()]); |
49 | |
50 | check<1,0>(indices[0]); |
51 | check<2,0>(indices[0][0]); |
52 | check<2,1>(indices[range()][0]); |
53 | check<2,1>(indices[0][range()]); |
54 | check<3,0>(indices[0][0][0]); |
55 | check<3,1>(indices[range()][0][0]); |
56 | check<3,1>(indices[0][range()][0]); |
57 | check<3,1>(indices[0][0][range()]); |
58 | check<3,2>(indices[range()][range()][0]); |
59 | check<3,2>(indices[range()][0][range()]); |
60 | check<3,2>(indices[0][range()][range()]); |
61 | |
62 | { |
63 | boost::detail::multi_array::index_gen<3,3> is1 = |
64 | indices[range(0,1,2)][range(1,2,3)][range(2,3,4)]; |
65 | BOOST_TEST(is1.ranges_[0] == range(0,1,2)); |
66 | BOOST_TEST(is1.ranges_[1] == range(1,2,3)); |
67 | BOOST_TEST(is1.ranges_[2] == range(2,3,4)); |
68 | } |
69 | |
70 | { |
71 | boost::detail::multi_array::index_gen<3,2> is2 = |
72 | indices[range(0,1,2)][2][range(2,3,4)]; |
73 | BOOST_TEST(is2.ranges_[0] == range(0,1,2)); |
74 | BOOST_TEST(is2.ranges_[1] == range(2)); |
75 | BOOST_TEST(is2.ranges_[1].is_degenerate()); |
76 | BOOST_TEST(is2.ranges_[2] == range(2,3,4)); |
77 | } |
78 | |
79 | return boost::report_errors(); |
80 | } |
81 | |
82 | |