Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-10-13 09:38:07


Gabriel Dos Reis wrote:
>
> Howard Hinnant <hinnant_at_[hidden]> writes:
>
> [...]
>
> | I do not believe it is a good argument for making
> | temporaries const. --c.end() is not inherently unsafe. It simply does
> | not work if the iterator turns out to be a pointer. This is a quirk of
> | the language and nothing more.
>
> Indeed. I see decrementation or incrementation as part of the
> iterator interface (supported operations) and from that perspective,
> it makes perfect sense to say --c.end(). I see no "unsafety" in that
> constructs.

It's not really unsafety, but it limits you in development, e.g. you
cannot have a "end"-object in your container and return a reference to
it. The reference must be const in order to work safely, so if you
change the function from

  iterator end() const;

to

  iterator& end() const;

it's not safe and if you change it to

  const iterator& end() const;

you'll break code. That is the reason why you should return a 'const
iterator' in the beginning, as it will allow you to transparently change
(optimize) your code later.

Regards, Daniel

--
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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