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

百般思念 提交于 2019-12-13 18:52:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!