<分区>
有一段类似于以下的代码:
#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
?