File: idxgen1.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 (81 lines) | stat: -rw-r--r-- 2,403 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 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.

//
// idxset1.cpp - testing the code for index_gen
//

#include "boost/multi_array/index_gen.hpp"
#include "boost/multi_array/index_range.hpp"
#include "boost/multi_array/types.hpp"
#include "boost/test/minimal.hpp"

#include "boost/array.hpp"

typedef boost::detail::multi_array::index index_type;
typedef boost::detail::multi_array::size_type size_type;
typedef boost::detail::multi_array::index_range<index_type,size_type> range;

template <int NumRanges, int NumDims>
void check(const boost::detail::multi_array::
           index_gen<NumRanges,NumDims>&) { }

bool operator==(const range& lhs,const range& rhs) {  
  return lhs.start_ == rhs.start_ &&
    lhs.finish_ == rhs.finish_ &&
    lhs.stride_ == rhs.stride_ &&
    lhs.degenerate_ == rhs.degenerate_;
}

int
test_main(int,char*[])
{

  boost::detail::multi_array::index_gen<0,0> indices;


  check<1,1>(indices[range()]);
  check<2,2>(indices[range()][range()]);
  check<3,3>(indices[range()][range()][range()]);

  check<1,0>(indices[0]);
  check<2,0>(indices[0][0]);
  check<2,1>(indices[range()][0]);
  check<2,1>(indices[0][range()]);
  check<3,0>(indices[0][0][0]);
  check<3,1>(indices[range()][0][0]);
  check<3,1>(indices[0][range()][0]);
  check<3,1>(indices[0][0][range()]);
  check<3,2>(indices[range()][range()][0]);
  check<3,2>(indices[range()][0][range()]);
  check<3,2>(indices[0][range()][range()]);

  {
    boost::detail::multi_array::index_gen<3,3> is1 =
      indices[range(0,1,2)][range(1,2,3)][range(2,3,4)];
    BOOST_CHECK(is1.ranges_[0] == range(0,1,2));
    BOOST_CHECK(is1.ranges_[1] == range(1,2,3));
    BOOST_CHECK(is1.ranges_[2] == range(2,3,4));
  }

  {
    boost::detail::multi_array::index_gen<3,2> is2 = 
      indices[range(0,1,2)][2][range(2,3,4)];
    BOOST_CHECK(is2.ranges_[0] == range(0,1,2));
    BOOST_CHECK(is2.ranges_[1] == range(2));
    BOOST_CHECK(is2.ranges_[1].is_degenerate());
    BOOST_CHECK(is2.ranges_[2] == range(2,3,4));
  }

  return boost::exit_success;
}