
23 Jul
2004
23 Jul
'04
4:55 p.m.
Rozental, Gennadiy wrote:
Hi,
I am trying to use construct similar to BOOST_FOREACH macro. In many cases I need to be able to detect whether loop was aborted with break or not.
BOOST_FOREACH( ... ) { }
// here if( aborted ) { .... } else { }
Is there way to do so?
There is a hidden variable in BOOST_FOREACH that tracks this information, but it is scoped, so you can't get at it. (And rightly so; the scoping of hidden control variables is what makes BOOST_FOREACH well-behaved.) You would have to do it like this: bool aborted = false; BOOST_FOREACH( ... ) { aborted = true; // your code here which could break aborted = false; } if( aborted ) ... -- Eric Niebler Boost Consulting www.boost-consulting.com