(C )将lambda函数存储在Boost Multi_Array中
(c++) Storing lambda function in a boost multi_array
我的计划是将数百个(甚至数千)(甚至数千个)函数存储在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); } );
i至少具有函数的" 7个维度"(例如Interp_list [6] [2] [3] [3] [3] [64] [12] [2]),因此喜欢循环循环。
编辑1.0:添加错误消息:
在/usr/include/boost/multi_array.hpp:hpp:26:0中包含的文件中 来自./storeinterp.cpp:16:/USR/include/boost/multi_array/multi_array_ref.hpp:在Instanziierung von»boost»boost :: multi_array_ref&amp;BOOST :: MULTI_ARRAY_REF :: OPerator =(constmultiarray&amp;)[带有constmultiarray = main()::::: iterator)>;t = std :: function>)>;长期未签名的int numdims = 2ul]«:/USR/include/boost/multi_array.hpp:371:26:erfordert durch»boost :: multi_array&amp;boost :: multi_array :: operator =(constmultiarray&amp;)[带有constmultiarray = main()::::: iterator)>;t = std :: function>)>;长无符号int numdims = 2ul;分配器= std ::分配器>)>>>]«./storeinterp.cpp:108:22:von Hier Erfordert/USR/include/boost/multi_array/multi_array_ref.hpp:hpp:482:30:fehler:»const struct main()::::: iterator)>«没有成员名称 »num_dimensions« BOOST_ASSERT(other.num_dimensions()== this-> num_dimensions());
您对interp2_list
的声明是错误的,您正在声明具有2个维度的boost::multi_array<>
的2-D数组但是最后两个维度没有任何程度。
您实际想要的是一个用正确尺寸初始初始化的boost::multi_array<>
:
boost::multi_array< std::function<double (std::vector<double>::iterator)>, 2>
interp2_list(boost::extents[2][2]);
请参阅Boost文档。
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- boost beast Websocket Multi Request Server/Client 并不是真正的 mul
- 如何使用 std::get 作为 boost-multi-index 容器键的global_fun
- 编译boost时"threading=multi"究竟做了什么
- Boost Multi Index标识索引
- Boost Multi Index:基于列表内容的索引
- Boost Multi-Index中的多个索引查询