File: idxgen1.cpp

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (83 lines) | stat: -rw-r--r-- 2,421 bytes parent folder | download
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
82
83
// 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/test/minimal.hpp"

#include "boost/array.hpp"
#include <cstddef>


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

bool operator==(const boost::detail::multi_array::
                index_range<int,std::size_t>& lhs,
                const boost::detail::multi_array::
                index_range<int,std::size_t>& rhs) {
  return lhs.start_ == rhs.start_ &&
    lhs.finish_ == rhs.finish_ &&
    lhs.stride_ == rhs.stride_ &&
    lhs.degenerate_ == rhs.degenerate_;
}

int
test_main(int,char*[])
{
  typedef boost::detail::multi_array::index_range<int,std::size_t> range;

  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;
}