|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2004-07-23 11:55:20
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk