如何将向量>>>>字节迭代到函数

How to iterate a deque>>vector>>bytes to a function

本文关键字:gt 迭代 函数 字节 向量      更新时间:2023-10-16

我需要能够调用一个函数,该函数正在寻找复杂数据结构(伪代码(的迭代器 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所做的那样。