Boost logo

Boost :

From: Alan Bellingham (alan_at_[hidden])
Date: 2003-10-01 05:14:11


Keith MacDonald wrote:

>Thanks for your constructive criticism. I've now changed the iterators,
>following your advice, and it looks a much neater solution, if only I could
>make it work :-(
>
>I've got a simple loop, like this:
>
> container3 c3;
> for (container3::const_iterator it = c3.begin(),
                                                 ^
Semi-colon meant? -------------------------------'

> it != c3.end();
> ++it)
> { ... }

My personal idiom - when I know the end iterator won't change - is

  container c;
  for (container::const_iterator it = c.begin(), end = c.end();
       it != end;
       ++it)
  { ... }

As a work-around, it might work better, since initialisation forces a
source-to-target conversion unlike comparison which may try conversions
on either side.

Alan

-- 
Alan Bellingham
(LJ: Bellinghman)

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk