0
的名单有这样的结构:修改列表
std::list<std::list<std::string>> data;
我需要去THROU顶层列表,并追加内部列表对一些标准。这样的事情:
std::for_each(data.begin(), data.end(),
[<some variable required for the logic>]
(const std::list<std::string>& int_list) {
if(...)
int_list.push_back(...);
});
你看到这段代码是无效的,因为for_each不能修改序列。 你会推荐我如何执行我所需要的(不需要修改初始数据结构)?
你能不能用['transform'(http://en.cppreference.com/w/cpp/algorithm/transform)? – EdChum
转换需要额外的副本,不是吗?从谓词返回 – amigo421
https://www.youtube.com/watch?v=YQs6IC-vgmo bjarne Stroustrup:为什么你应该避免列表 –