【问题标题】:Updating a boost multi_array variable in a loop that changes its size在更改其大小的循环中更新 boost multi_array 变量
【发布时间】:2016-10-21 20:41:01
【问题描述】:

我有一个更新 boost::multi_array 的函数,它改变了大小。当数组改变大小时,有没有办法在循环中更新数组(即在初始化后更新它)?初始化后如何更新(分配)boost::multi_array

#include <boost/multi_array.hpp>
#include <iostream>

typedef boost::multi_array<int, 2> A;

A update(const A& a) {
    auto s = a.shape()[0];
    A b{boost::extents[s+s][3]};
    auto b_mid = std::copy(a.begin(), a.end(), b.begin());
    std::copy(a.begin(), a.end(), b_mid);
    return b;
}

int main() {
    A a {boost::extents[5][3]};
    int r = 5;
    while (r--) {
        a =             // causes error because the size has changed the sizes of RHS and LHS don't match.
            update(a);  // Alternatively: a = std::move(update(a));
    }
}

问题是A 类型的赋值运算符不能改变multi_arrayarray 的大小。请注意,我使用 C++14。使用 std::move() 没有帮助。

【问题讨论】:

    标签: c++ c++11 boost c++14


    【解决方案1】:

    .reshape 是你想要的。

    【讨论】:

      猜你喜欢
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      相关资源
      最近更新 更多