How do you assign a boost::indices in a variable?

2019-07-23 15:02发布

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?

0条回答
登录 后发表回答