C++ Boost多维阵列

C++ Boost多维阵列,c++,boost,iterator,boost-multi-array,C++,Boost,Iterator,Boost Multi Array,我有一个Boost multiarray,它的尺寸是在运行时根据用户的输入设置的 现在我想通过x,y,z组件对该数组进行迭代 如果这是一个std::vector,我会使用: for(int i=0;i<v.size();i++){ 对于(int i=0;i#包括“boost/multi_array.hpp” #包括 #include您可以使用shape()来减少复杂度: #include <iostream> #include <string> #include

我有一个Boost multiarray,它的尺寸是在运行时根据用户的输入设置的

现在我想通过
x,y,z
组件对该数组进行迭代

如果这是一个std::vector,我会使用:

for(int i=0;i<v.size();i++){
对于(int i=0;i
#包括“boost/multi_array.hpp”
#包括
#include

您可以使用
shape()
来减少复杂度:

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

int main() {
    boost::multi_array<std::string, 2> a(boost::extents[3][5]);
    for(size_t x = 0; x < a.shape()[0]; x++) {
        for(size_t y = 0; y < a.shape()[1]; y++) {
            std::ostringstream sstr;
            sstr << "[" << x << ", " << y << "]";
            a[x][y] = sstr.str();
        }
    }
    for(size_t x = 0; x < a.shape()[0]; x++) {
        for(size_t y = 0; y < a.shape()[1]; y++) {
            std::cout << a[x][y] << "\n";
        }
    }
    return 0;
}
#包括
#包括
#包括
int main(){
boost::multi_数组a(boost::区段[3][5]);
对于(大小x=0;xsstr谢谢。这看起来太复杂了,所以我研究了一些问题,我将尝试使用boost uBLAS矩阵。我曾经对uBLAS和共享指针有过一些“乐趣”,不记得细节了。看看C++11中的元组类型怎么样?
#include <iostream>
#include <string>
#include <boost/multi_array.hpp>

int main() {
    boost::multi_array<std::string, 2> a(boost::extents[3][5]);
    for(size_t x = 0; x < a.shape()[0]; x++) {
        for(size_t y = 0; y < a.shape()[1]; y++) {
            std::ostringstream sstr;
            sstr << "[" << x << ", " << y << "]";
            a[x][y] = sstr.str();
        }
    }
    for(size_t x = 0; x < a.shape()[0]; x++) {
        for(size_t y = 0; y < a.shape()[1]; y++) {
            std::cout << a[x][y] << "\n";
        }
    }
    return 0;
}