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 // access.cpp - operator[] and operator() tests with various arrays 15 // The tests assume that they are working on an Array of shape 2x3x4 16 // 17 18 #include "generative_tests.hpp" 19 #include <boost/static_assert.hpp> 20 21 template <typename Array> access(Array & A,const mutable_array_tag &)22void access(Array& A, const mutable_array_tag&) { 23 assign(A); 24 access(A,const_array_tag()); 25 26 const Array& CA = A; 27 access(CA,const_array_tag()); 28 } 29 30 template <typename Array> access(Array & A,const const_array_tag &)31void access(Array& A, const const_array_tag&) { 32 const unsigned int ndims = 3; 33 BOOST_STATIC_ASSERT((Array::dimensionality == ndims)); 34 typedef typename Array::index index; 35 const index idx0 = A.index_bases()[0]; 36 const index idx1 = A.index_bases()[1]; 37 const index idx2 = A.index_bases()[2]; 38 39 // operator[] 40 int cnum = 0; 41 const Array& CA = A; 42 for (index i = idx0; i != idx0+2; ++i) 43 for (index j = idx1; j != idx1+3; ++j) 44 for (index k = idx2; k != idx2+4; ++k) { 45 BOOST_TEST(A[i][j][k] == cnum++); 46 BOOST_TEST(CA[i][j][k] == A[i][j][k]); 47 } 48 49 // operator() 50 for (index i2 = idx0; i2 != idx0+2; ++i2) 51 for (index j2 = idx1; j2 != idx1+3; ++j2) 52 for (index k2 = idx2; k2 != idx2+4; ++k2) { 53 boost::array<index,ndims> indices; 54 indices[0] = i2; indices[1] = j2; indices[2] = k2; 55 BOOST_TEST(A(indices) == A[i2][j2][k2]); 56 BOOST_TEST(CA(indices) == A(indices)); 57 } 58 ++tests_run; 59 } 60 main()61int main() { 62 return run_generative_tests(); 63 } 64