如何将向量>>>>字节迭代到函数
How to iterate a deque>>vector>>bytes to a function
我需要能够调用一个函数,该函数正在寻找复杂数据结构(伪代码(的迭代器 vector::d eque::vector(uint8_t(::iterator。我需要能够用 deque::vector(uint8_t( 调用它;我不知道如何"迭代"它。
在下面的代码段中,我尝试使用 someMoreBytes deque 结构调用 MyFunkyFunc 函数。
#include <cstdlib>
#include <vector>
#include <deque>
#include "stdint.h"
using namespace std;
void MyFunkyFunc(std::vector<std::deque<std::vector<uint8_t>>>::iterator itsIt)
{
}
int
main(int argc, char** argv)
{
std::vector<std::deque<std::vector < uint8_t>>> bunchaBytes;
std::deque<std::vector<uint8_t>> someMoreBytes;
//... Put at least one element in bunchaBytes
MyFunkyFunc(bunchaBytes.begin());
MyFunkyFunc(someMoreBytes); // Problem is here
return 0;
}
这个代码存根是接近的,因为我可以得到原始代码;我无法对MyFunkyFunc函数进行任何修改,因为它位于我必须链接的库中。提前非常感谢
如果我们假设MyFunkyFunc
被正确实现为接受迭代器参数的模板:
template <typename I>
void MyFunkyFunc (I itsIt) {
//...
}
然后,你可以只传递someMoreBytes
的地址,因为向量的迭代器的行为与向量元素的地址相同。
MyFunkyFunc(&someMoreBytes);
否则,你需要将someMoreBytes
重新定义为单个元素vector
,并传入begin()
,就像你对bunchaBytes
所做的那样。
相关文章:
- 使用std::multimap迭代器创建std::list
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++中带有List类的迭代器Segfault
- 迭代时从向量和内存中删除对象
- 如何在c++迭代器类型中包装std::chrono
- 带过滤器的现代迭代c++集合
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- C++矢量迭代
- 集合上的输出迭代器:assign和increment迭代器
- Boost Spirit,获取迭代器内部语义动作
- 擦除while循环中迭代的元素
- 实现一个在集合上迭代的模板函数
- 对于set上的循环-获取next元素迭代器
- 在向量内的向量上迭代
- 为什么output_editor Concept不需要output_e迭代器标记
- TSP递归解的迭代形式
- c++17文件系统::recursive_directory迭代器()在mac上没有给出这样的目录,但在windows上
- 使用迭代器时如何访问对象在向量中的位置?
- std::vector::迭代器是否可以合法地作为指针
- 跟随整数索引列表的自定义类迭代器