Topic: Which methods for associative containers invoke comparison predicate?
Author: mleonov@my-deja.com
Date: 1999/10/08 Raw View
In article <DWRK3.4962$z5.201215@ndnws01.ne.mediaone.net>,
"Dave Abrahams" <abrahams@mediaone.net> wrote:
> In article <7tdhnu$ck5$1@nnrp1.deja.com> , mleonov@my-deja.com wrote:
>
> > The Standard is not clear on which methods of associative containers
> > invoke comparison predicate and which don't.
> > For example, do clear(), erase(iterator, iterator) and erase
(iterator)
> > invoke comparison predicate? In the current implementations they
don't,
> > but is this guaranteed by Standard?
> <snip>
> The best we can say is that it's highly unlikely that an
implementation
> would ever do this.
Yes, I agree that it's almost impossible. So my suggestion is that
future version of Standard should be more clear on this issue (when
predicate is invoked). Defect report?
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: mleonov@my-deja.com
Date: 1999/10/07 Raw View
In article <slrn7vlaga.pl3.sbnaran@localhost.localdomain>,
sbnaran@uiuc.edu wrote:
>
> On 05 Oct 99 20:15:01 GMT, mleonov@my-deja.com <mleonov@my-deja.com>
wrote:
>
> >The Standard is not clear on which methods of associative containers
> >invoke comparison predicate and which don't.
> >For example, do clear(), erase(iterator, iterator) and erase
(iterator)
> >invoke comparison predicate? In the current implementations they
don't,
> >but is this guaranteed by Standard?
>
> Why do you care?
Suppose someone has an associative container, say map, which stores
pointers to objects. Before deleting the map he deletes those objects.
If the Standard guarantees that clear() and erase(iterator) don't
invoke comparison predicate this is safe thing to do, otherwise not. Of
course I know that there are better ways to store allocated objects in
containers (smart pointers, adapters etc.), but I still think many
people use containers this way.
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: "Dave Abrahams" <abrahams@mediaone.net>
Date: 1999/10/07 Raw View
In article <7tdhnu$ck5$1@nnrp1.deja.com> , mleonov@my-deja.com wrote:
> The Standard is not clear on which methods of associative containers
> invoke comparison predicate and which don't.
> For example, do clear(), erase(iterator, iterator) and erase(iterator)
> invoke comparison predicate? In the current implementations they don't,
> but is this guaranteed by Standard?
Well, there is no explicit guarantee, but:
There is a guarantee that none of these functions throws an exception. Since
your comparison function is allowed to throw, an implementation would have
to "eat" the exception to be conforming if it called your comparison
function. In other words, the implementation would not be exception-neutral.
Furthermore, the erase operation is required to complete and produce the
expected result, even if the comparison fails to return a result due to an
exception... so the call to your comparison function was unneccessary after
all. Only some sort of adaptive implementation which would use your
comparison if possible, but back off to a slower algorithm that required no
comparison is plausible for this sort of scenario.
Finally, since the container already has its items stored in sorted order,
and it has no way of coming up with new values of the contained element
type, why would it ever need to call your comparison function when erasing
elements?
The best we can say is that it's highly unlikely that an implementation
would ever do this.
-Dave
---
[ 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: mleonov@my-deja.com
Date: 1999/10/05 Raw View
The Standard is not clear on which methods of associative containers
invoke comparison predicate and which don't.
For example, do clear(), erase(iterator, iterator) and erase(iterator)
invoke comparison predicate? In the current implementations they don't,
but is this guaranteed by Standard?
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: sbnaran@uiuc.edu (Siemel B. Naran)
Date: 1999/10/06 Raw View
On 05 Oct 99 20:15:01 GMT, mleonov@my-deja.com <mleonov@my-deja.com> wrote:
>The Standard is not clear on which methods of associative containers
>invoke comparison predicate and which don't.
>For example, do clear(), erase(iterator, iterator) and erase(iterator)
>invoke comparison predicate? In the current implementations they don't,
>but is this guaranteed by Standard?
Why do you care?
--
--------------
siemel b naran
--------------
[ 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 ]