问题
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?
来源:https://stackoverflow.com/questions/35556450/how-do-you-assign-a-boostindices-in-a-variable