【发布时间】:2016-06-29 12:47:18
【问题描述】:
我的计划是在 boost 库中的多维数组 multi_array 中存储数百个(甚至数千个)(插值)函数。我需要存储它们,因为我需要在项目的不同点使用不同的数字作为参数调用它们。 (我正在使用 linterp 库 http://rncarpio.github.io/linterp/ 创建插值函数)。
我可以将函数存储在一个向量中,如下所示:
// creating the vector, storing the function
std::vector< std::function< double(double *x) > > interp_list(4);
// storing the function in the vector
interp_list[0] = ( [&] (double *x) { return interp1.interp(x); } );
但是对多维数组尝试同样的操作总是会导致编译错误:
// creating the array, I want to store the functions in
boost::multi_array< std::function<double (std::vector<double>::iterator)>, 2> interp2_list[2][2];
// storing the function in the vector
interp2_list[0][0] = ( [&] (std::vector<double>::iterator x) { return interp1.interp(x); } );
我的函数至少有“7 个维度”(例如 interp_list[6][2][3][3][64][12][2]),因此喜欢循环它。
编辑 1.0: 添加错误信息:
在 /usr/include/boost/multi_array.hpp:26:0 包含的文件中, 来自./StoreInterp.cpp:16: /usr/include/boost/multi_array/multi_array_ref.hpp: Instanziierung von »boost::multi_array_ref& boost::multi_array_ref::op erator=(const ConstMultiArray&) [with ConstMultiArray = main()::::iterator)>; T = std::function >)>; long unsigned int NumDims = 2ul]«: /usr/include/boost/multi_array.hpp:371:26: erfordert durch »boost::multi_array& boost::multi_array::o perator=(const ConstMultiArray&) [with ConstMultiArray = main()::::iterator)>; T = std::function >)>; long unsigned int NumDims = 2ul;分配器 = std::allocator >)> >]« ./StoreInterp.cpp:108:22: von hier erfordert /usr/include/boost/multi_array/multi_array_ref.hpp:482:30: Fehler: »const struct main()::::iterator)>« 没有名为的成员 »num_dimensions« BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
【问题讨论】:
-
编译错误通常伴随着错误信息。你读过那封邮件吗?它说什么?
标签: c++ function boost multidimensional-array lambda