Topic: Return values of fill and generate
Author: Rich Paul <linguist@cyberspy.com>
Date: 1996/09/05 Raw View
Hyman Rosen wrote:
> I'm curious as to why the fill and generate algorithms in STL don't return
> the past-the-end iterator instead of returning nothing. I have code which
> I would like to write like this:
>
> p = a.begin();
> p = fill(p, p + i, WHITE);
> p = fill(p, p + j, BLACK);
>
> Instead, I have to say:
>
> p = a.begin();
> fill(p, p + i, WHITE);
> p += i;
> fill(p, p + j, BLACK);
> p += j;
>
> What is there to lose by having a return value?
I'd agree, and add the char_traits template to the list. Right now,
copy, move, etc all return a pointer to the start of the memory that's
being copied or moved. I'd prefer a pointer one past the end of the
memory that's being copied or moved, so I know where to continue my
operator.
There it is even more annoying, because I have an integer and an
iterator, not two iterators.
--
#include <legalbs/standarddisclaimer>
Rich Paul | If you like what I say, tell my
C++, OOD, OOA, OOP, | employer, but if you don't,
OOPs, I forgot one ... | don't blame them. ;->
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: hymie@panix.com (Hyman Rosen)
Date: 1996/08/29 Raw View
I'm curious as to why the fill and generate algorithms in STL don't return
the past-the-end iterator instead of returning nothing. I have code which
I would like to write like this:
p = a.begin();
p = fill(p, p + i, WHITE);
p = fill(p, p + j, BLACK);
Instead, I have to say:
p = a.begin();
fill(p, p + i, WHITE);
p += i;
fill(p, p + j, BLACK);
p += j;
What is there to lose by having a return value?
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]