How to concat two existing ranges::view?

给你一囗甜甜゛ 提交于 2019-12-06 17:00:41

You can't compose views this way. Concatenating a view yields an object with a different type. You can't assign it back to the original view because its type is different.

You can get the effect you're after with a combination of view::cycle (takes one range and repeats it infinitely), and view::take (takes the first N elements of a range).

vector<int> const & v{foo()}; // returns a reference
auto rng = v | view::cycle | view::take(5 * v.size());

EDIT

If foo() can return a reference to a different vector each time, then you can use view::generate and view::join, in addition to view::take:

auto rng = view::generate(foo) | view::take(5) | view::join;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!