Std:: boost::数组列表
std::list of boost::arrays
我在使用数组列表时遇到了一些麻烦。因此,为了澄清问题,我知道std::list不能包含数组。我正在使用boost::array来做到这一点。
目前,我对我的寻路算法所需的所有数据类型进行原型化,并测试它们的速度和缓存一致性。
typedef boost::array<int,2> VertexB2i;
typedef std::list<VertexB2i> VertexList;
这些类型不用于寻路,它们比所有真正的c++数组和寻路器标志更容易使用,所以它们只用于生成导航网格。(我也知道在这种情况下我可以使用stl::pair来代替boost::数组,但我想保持生成的数据尽可能与寻路器数据相似,所以我不必一直处理两个完全不同的接口)
VertexList* vl = new VertexList();
vl->push_back({{8,28}}); // this does not work, why?
因此,在为这两种数据类型设置一些测试数据时,我注意到注释行不起作用,尽管这确实起作用:
VertexList* vl = new VertexList();
VertexB2i ver1 = {{8,28}};
vl->push_back({ver1}); // works
总结一下:在不首先宣布"VertexB2i"为独立的情况下,是否有办法推迟"VertexB2i"?一般的建议?
std::array
(或boost::array
)是聚合类型。在c++ 98/03中,它只能在声明器中初始化:
std::array<int, 2> arr = { 1, 2 };
thelist.push_back(arr); // makes a copy
在c++ 11中,您也可以使用统一初始化来创建临时:
std::list<std::array<int,2>> l;
l.push_back(std::array<int,2>{{2,3}}); // maybe copy
l.emplace_back(std::array<int,2>{{2,3}}); // maybe copy, probably optimized out
相关文章:
- C++如何生成std::数组列表
- 在数组中输入 n 个整数的列表,并以类似于钟摆来回移动的方式排列它们. 输入-1 3 2 5 4,输出5 3 1 2 4
- C++未知长度字符串的数组,其行为类似于 Python 字符串列表
- GTEST : 如何将数组列表作为参数传递到 ValuesIn of INSTANTIATE_TEST_CASE_P?
- 基于数组的列表 - 动态数组创建时出错
- 如何使用列表/数组在C++中实现 Python "... not in ..."?
- 从非托管 C# DLL 返回列表/数组
- C++对象列表数组
- 如何在C++中创建配对列表数组
- 链接列表数组
- 获取列表数组中的所有列表项
- 如何创建和扫描列表/数组..在嵌入式剪辑中
- 列表数组<string>,插入字符串行为奇怪
- 对 STL 列表数组使用迭代器的语法
- 在类|C++中创建分数列表数组
- C++是否有一些类似C#类型的东西来存储列表/数组中的类类型
- 列表数组-构造函数和main()中的地址不匹配
- c++中的列表数组.指针;/
- STL 列表数组无法访问列表函数
- 用动态内存管理创建类列表数组