From: Thomas Witt (witt_at_[hidden])
Date: 2002-05-17 03:45:42
On Friday 17 May 2002 10:08, Daniel Frey wrote:
> "Victor A. Wagner, Jr." wrote:
> > At Wednesday 2002/05/15 08:45, you wrote:
> > > return !cont.empty() && ++cont.begin() == cont.end();
> > As Scott Meyers points out in his "Effective STL", ++cont.begin() MAY NOT
> > compile, depending on the implementation. That's a _serious_ drawback,
> > IMO. Slow (for stupid compilers) beats not compiling any day.
> I have to read this book. :-( If this is true, you are absolutely right
> to use 'boost::next()'. But why doesn't it work? The only thing I could
> think of is, that 'begin()' returns a 'const iterator&' or something
> like that. Is this allowed? Or is there any other reason?
The basic problem is, that you are not allowed to modify temporaries of
built-in types. So if iterator is just a typedef for int*, ++cont.begin()
will not compile.
You can try it if you have access to STLport.
vector<int>() rg(0, 2);
will compile in debug mode but not in normal mode.
The reason is in debug mode iterators are UDTs as they have to do the
checking, in normal mode they are plain pointers.
-- Dipl.-Ing. Thomas Witt Institut fuer Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover voice: +49(0) 511 762 - 4273, fax: +49(0) 511 762-3001 http://www.ive.uni-hannover.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk