【发布时间】:2017-05-26 13:16:55
【问题描述】:
具有与以下类似的代码:
#include <iostream>
#include <vector>
int main()
{
std::vector<std::string> v1, v2;
for (const auto& s : v1) {
// do something with s
}
for (const auto& s : v2) {
// do something with s
}
}
我想一次性遍历v1 和v2 中的所有元素(由于这些循环中的逻辑有点困难,我不能在其中使用函数——为了这个问题)。
所以理想的解决方案是这样的:
for (const auto& s : magic(v1,v2)) {
// do something with s
}
显然没有分配所有复制到其中的元素的新容器(因为该解决方案是微不足道的。
有什么类似的吗?在boost?
【问题讨论】:
标签: c++ loops boost iterator containers