范围::视图::生成具有发电机函数信号范围的范围
我想拥有一个像Python一样终止的生成器,但是如果支持此功能,我无法从范围:: views :: views :: generate
的接口。
I'd like to have a generator that terminates, like python, but I can't tell from ranges::views::generate
's interface if this is supported.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以轻松地手动滚动:
https://godbolt.org/z/xcgz666657r 尽管使用coroutine Generator可能会更好有一个可用。
您可以在发电机中返回可选的,并在使用
nullopt
使用视图生成
std :: nullopt
时停止获取元素。You can roll it by hand easily enough:
https://godbolt.org/z/xcGz6657r although it's probably better to use a coroutine generator if you have one available.
You can return an optional in the generator, and stop taking elements when a
std::nullopt
is generated withviews::take_while