File: access.cpp

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (63 lines) | stat: -rw-r--r-- 1,874 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2002 The Trustees of Indiana University.

// Use, modification and distribution is subject to the Boost Software 
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//  Boost.MultiArray Library
//  Authors: Ronald Garcia
//           Jeremy Siek
//           Andrew Lumsdaine
//  See http://www.boost.org/libs/multi_array for documentation.

// 
// access.cpp - operator[] and operator() tests with various arrays
//    The tests assume that they are working on an Array of shape 2x3x4
//

#include "generative_tests.hpp"
#include "boost/static_assert.hpp"

template <typename Array>
void access(Array& A, const mutable_array_tag&) {
  assign(A);
  access(A,const_array_tag());

  const Array& CA = A;
  access(CA,const_array_tag());
}

template <typename Array>
void access(Array& A, const const_array_tag&) {
  const unsigned int ndims = 3;
  BOOST_STATIC_ASSERT((Array::dimensionality == ndims));
  typedef typename Array::index index;
  const index idx0 = A.index_bases()[0];
  const index idx1 = A.index_bases()[1];
  const index idx2 = A.index_bases()[2];

  // operator[]
  int cnum = 0;
  const Array& CA = A;
  for (index i = idx0; i != idx0+2; ++i)
    for (index j = idx1; j != idx1+3; ++j)
      for (index k = idx2; k != idx2+4; ++k) {
        BOOST_CHECK(A[i][j][k] == cnum++);
        BOOST_CHECK(CA[i][j][k] == A[i][j][k]);
      }

  // operator()
  for (index i2 = idx0; i2 != idx0+2; ++i2)
    for (index j2 = idx1; j2 != idx1+3; ++j2)
      for (index k2 = idx2; k2 != idx2+4; ++k2) {
        boost::array<index,ndims> indices;
        indices[0] = i2; indices[1] = j2; indices[2] = k2;
        BOOST_CHECK(A(indices) == A[i2][j2][k2]);
        BOOST_CHECK(CA(indices) == A(indices));
      }
  ++tests_run;
}

int test_main(int,char*[]) {
  return run_generative_tests();
}