1

I am trying to store a boost::indices in a variable. From what I can gather, this produces an index_gen type. However, index_gen seems to be templated in boost::detail, but the template parameters are not exposed to multi_array::index_gen, and they seem to default to <0,0>, which produces the error you'll see below:

I have tried the following:

#include "boost/multi_array.hpp"

int main()
{
    typedef boost::multi_array<double, 3> array_type;
    using IndexType = boost::array<array_type::index, 3>;
    array_type A;
    A.reshape(IndexType({{3,4,2}}));

// this works
    array_type::array_view<3>::type myview =
      A[ boost::indices[array_type::index_range(0,2)][array_type::index_range(1,3)][array_type::index_range(0,4)] ];

// This produces a compiler error:
    array_type::index_gen test = boost::indices[array_type::index_range(0,2)][array_type::index_range(1,3)][array_type::index_range(0,4)];

}

The error is:

error: conversion from 'boost::detail::multi_array::index_gen<3, 3>' to non-scalar type 'boost::detail::multi_array::multi_array_base::index_gen {aka boost::detail::multi_array::index_gen<0, 0>}' requested
     array_type::index_gen test = boost::indices[array_type::index_range(0,2)][array_type::index_range(1,3)][array_type::index_range(0,4)];

Any thoughts on how to store this index object?

David Doria
  • 9,873
  • 17
  • 85
  • 147
  • This seems to work: `boost::detail::multi_array::index_gen<3,3> test = boost::indices[array_type::index_range(0,2)][array_type::index_range(1,3)][array_type::index_range(0,4)];`, but it seems odd to have to use something from the `detail` namespace? – David Doria Feb 23 '16 at 15:01
  • @Antonio With this: `array_type::index_gen<3,3> indices2 = boost::indices[array_type::index_range(0,2)][array_type::index_range(1,3)][array_type::index_range(0,4)];` I get `error: 'boost::detail::multi_array::multi_array_base::index_gen {aka boost::detail::multi_array::index_gen<0, 0>}' is not a template array_type::index_gen<3,3> indices2 = boost::indices[array_type::index_range(0,2)][array_type::index_range(1,3)][array_type::index_range(0,4)]; ^` – David Doria Feb 25 '16 at 16:33
  • Indeed the correct `index_gen` is defined in `boost::detail::multi_array`. The `index_gen` in `boost::multi_array` is a `typedef` to `boost::detail::multi_array::index_gen<0,0>` (in multi_array/base.hpp). Not clear to me why. Maybe worth another question. – Antonio Feb 25 '16 at 16:50
  • @Antonio Posted: http://stackoverflow.com/questions/35633531/why-is-index-gen-in-multi-array-a-boostdetailmulti-arrayindex-gen0-0 – David Doria Feb 25 '16 at 16:55

0 Answers0