Topic: Standard library questions.
Author: dirk@sallust.ida.ing.tu-bs.de (Dirk Herrmann)
Date: 1997/05/30 Raw View
Hello!
Is there a reason why the following features are not included
in the standard library?
1) operator[] for const maps
The lack of this operator seems to be an unecessary restriction,
since it would be possible to throw an exception if a non-existent
key was queried with this operator.
The way it is defined today forces me to use find() if I want
to work with a const map, even if I know which entries do
exist. Since the operator[] syntax is easier to read, I
then prefer not to use const maps. (You may disagree whether it
is the right choice :).
2) bool contains(key) for sets and maps
Meanwhile, the standard contains a 'clear' method for all
containers, which allows to avoid the ugly and error-prone
aContainer.erase(aContainer.begin(), aContainer.end())
But why isn't there some 'contains' (or similar) function,
that could save me from typing
anAssociative.find(key) != anAssociative.end()
Any hints?
--
Best regards,
Dirk Herrmann
---
[ 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 ]