打破std :: for_each循环 [英] Breaking in std::for_each loop
本文介绍了打破std :: for_each循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用std :: for_each算法时,如果满足某个条件,我该如何断开?
解决方案
算法,它将停止并返回迭代器,其中应用于迭代元素的谓词条件返回true。所以你的谓词应该改成返回一个布尔作为continue / break条件。
但是,这是一个黑客,所以你可以使用算法。
另一种方法是使用BOOST_FOREACH。
While using std::for_each algorithm how do I break when a certain condition is satisfied?
解决方案
You can use find_if algorithm, which will stop and return the iterator where the predicate condition applied to the iterated element returns true. So your predicate should be changed to return a boolean as the continue/break condition.
However, this is a hack, so you can use the algorithms.
Another way is to use BOOST_FOREACH.
这篇关于打破std :: for_each循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文