From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2005-04-26 11:44:10


"Pavel Vozenilek" <pavel_vozenilek_at_[hidden]> wrote in message
news:d4lq0a$is1$1_at_sea.gmane.org...
>
> "Gennadiy Rozental" wrote:
>> The formal review of Eric Nibbler's FOREACH macro starts
>>
>> http://boost-sandbox.sourceforge.net/vault/index.php?directory=eric_niebler
>> foreach.zip
>>
>
> I use FOREACH and like it. It should be part of Boost.
>
>
> The only time when I needed to fall back on old for(;;)
> was when I wanted to know whether I am within first/last
> loop cycle, like in:
>
> for (int i = 0; i < n; ++i)
> {
> if (i == 0) cout << "[";
> ...
> if (i + 1 == n) cout << "]";
> }

Yeah. From time to time (but quite consistently) I also need first/last
variable inside loop. You could use FOREACH with first:

bool first = true;
BOOST_FOREACH(... ) {
     if( first ) {
        ....
       first = false;
    }
}

I guess macro could provide this automatically, but I am not sure this
convenience warrant an overhead for those who do not need it.

Gennadiy