Topic: Q: Items in associative containers need == and < ?
Author: matt@cyclops5.berkeley.edu (Matt Austern)
Date: 1995/11/01 Raw View
In article <477o7e$5pd@info.uci.kun.nl> Marian Hellema <marian@atcmp.nl> writes:
> The ObjectSpace documentation states:
> "All the items that are stored in associative containers must be
> comparable using == and <">
> I have not been able to find a confirmation for this rule in the
> standard working paper. Can someone clear this up for me?
All of the associative containers in the STL require that a comparison
function be defined for items in the container, but it does not
necessarily have to use operator <. (See section 23.3 of the draft
standard.) One of the template parameters of the associative
containers is a comparison function object used to compare items in
the container. By default the comparison object is less<Key>, meaning
that it uses operator <, but you may provide a different type if you
want to store objects for which operator < is undefined.
(Note, incidentally, that you may pass a comparison object in the
container's constructor: each container may have its own comparison
object. This argument defaults to Compare(), which, again, defaults
to less<Key>().)
It's still true that you must define an ordering for whatever type
you're putting in the container; you simply aren't required to use
operator <. Associative containers that you can use for unordered
keys would also be useful, but a proposal to add them to the standard
was rejected.
--
Matt Austern He showed his lower teeth. "We
matt@physics.berkeley.edu all have flaws," he said, "and
http://dogbert.lbl.gov/~matt mine is being wicked."
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: ajay@lehman.com (Ajay Kamdar)
Date: 1995/11/03 Raw View
In article <47ai5s$54b@jabba.lehman.com>, Ajay Kamdar <ajay@lehman.com> wrote:
>My reading of 23.1.3 of the April WP indicated that operator == should
>not be required by the associative containers.
Typo: That should have been 23.1.2.3.
--
Ajay Kamdar | Email: ajay@lehman.com | Standard Disclaimer
Lehman Brothers | Phone: (201) 524-5048 |
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: Marian Hellema <marian@atcmp.nl>
Date: 1995/11/01 Raw View
I am using ObjectSpace's STL<Toolkit>.
The ObjectSpace documentation states:
"All the items that are stored in associative containers must be
comparable using == and <"
I have not been able to find a confirmation for this rule in the
standard working paper. Can someone clear this up for me?
Thanks,
Marian
--
----------------------------------------------------------------------
Marian Hellema AT Computing, UNIX training and consultancy
email: marian@atcmp.nl P.O. Box 1428, 6501 BK Nijmegen
phone: +31 24 3527225 the Netherlands
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]