gpt4 book ai didi

c++ - 如何将 deque>>vector>>bytes 迭代到函数

转载 作者:行者123 更新时间:2023-11-30 03:14:22 25 4
gpt4 key购买 nike

我需要能够调用一个正在寻找复杂数据结构(伪代码)vector::deque::vector(uint8_t)::iterator 的迭代器的函数。我需要能够用 deque::vector(uint8_t); 调用它我不知道如何“迭代”它。

在下面的代码段中,我尝试使用 someMoreBytes 双端队列结构调用 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;
}

这个代码 stub 是接近原始代码的部分;我无法对 MyFunkyFunc 函数进行任何修改,因为它位于我必须链接的库中。非常感谢

最佳答案

如果我们假设 MyFunkyFunc 被正确实现为接受迭代器参数的模板:

template <typename I>
void MyFunkyFunc (I itsIt) {
//...
}

然后,您可以只传递 someMoreBytes 的地址,因为 vector 的迭代器的行为与 vector 元素的地址相同。

MyFunkyFunc(&someMoreBytes);

否则,你需要重新定义someMoreBytes为单个元素vector,并传入begin(),就像你用 bunchaBytes 做了。

关于c++ - 如何将 deque>>vector>>bytes 迭代到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57879528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com