Breaking in std::for_each loop

前端 未结 7 1361
南方客
南方客 2021-01-01 10:37

While using std::for_each algorithm how do I break when a certain condition is satisfied?

相关标签:
7条回答
  • 2021-01-01 11:25

    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.

    0 讨论(0)
提交回复
热议问题