Topic: What is elimination?
Author: Lisa Lippincott <lisa_lippincott@bigfix.com>
Date: 2000/01/26 Raw View
I've just taken a fresh look at the definitions of remove and unique.
Here, for reference, is the definition of remove:
Effects: Eliminates all the elements referred to by iterator i in the
range [ first, last) for which the following corresponding conditions
hold: *i == value, pred(*i) != false.
Returns: The end of the resulting range.
Notes: Stable: the relative order of the elements that are not removed
is the same as their relative order in the original range.
Now we all know what remove does -- it segregates the elements, so that
the "removed" elements appear after those not removed. That is,
after remove,
the predicate has been applied to all the elements of [first,last);
elements which satisfied the predicate are in [result, last); and
the other elements are in [first, result), in their original order.
But I can't see how the definition conveys this meaning. My first
thought was "eliminate must be a term defined elsewhere." But I
haven't found a technical definition for eliminate. And I can't see
how "move to the back of the line" is a plain language definition of
eliminate.
Can anyone argue that this definition really expresses what remove
does?
--Lisa Lippincott
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Pavel Mayer" <pavel@datango.de>
Date: 2000/01/28 Raw View
Lisa Lippincott <lisa_lippincott@bigfix.com> wrote:
>
> Now we all know what remove does -- it segregates the elements, so that
> the "removed" elements appear after those not removed. That is,
> after remove,
>
> the predicate has been applied to all the elements of [first,last);
>
> elements which satisfied the predicate are in [result, last); and
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Where did you get this from ? In fact, nothing can be said about these
predicate-satisfying elements except that none of them is in the range
[first,last) anymore, which is not the same as being in in [result, last); .
>
> the other elements are in [first, result), in their original order.
>
> But I can't see how the definition conveys this meaning. My first
> thought was "eliminate must be a term defined elsewhere." But I
> haven't found a technical definition for eliminate. And I can't see
> how "move to the back of the line" is a plain language definition of
> eliminate.
>
> Can anyone argue that this definition really expresses what remove
> does?
>
No, this is the definition of stable_partition, not the definition of
remove.
Eliminating here means that these elements are not accessible anymore; they
may be already overwritten or still live in [result, last), but that depends
on the implemention, their original location and the ratio of predicate
satisfying to no-satisfying elements. OTOH, they are not necessarily
destroyed at this time, but will finally when the container is destroyed.
What usually happens is that all non-predicate satisfying are copied to
[begin,result) and all other elements are left untouched.
But dont worry, you are not the only person who intuitively thought that the
predicate satisfying elements must go somewhere. There is currently a thread
on comp.lang.c++.moderated ("The list.erase(remove...) idiom, doing half the
job???") that might be of interest for you.
Peace and Prosperity
--
Pavel Mayer (pavel@datango.de)
"Without chaos, nothing is created. Without order, nothing can exist."
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]