🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2384

Re: Q: Items in associative containers need == and < ?

#2384
From: Matt Austern
Date: Wed, 01 Nov 1995 19:29
39 lines
2383 bytes
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. ]
Technical Details
Message-ID: <MATT.95Nov1112558@cyclops5.berkeley.edu>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <477o7e$5pd@info.uci.kun.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: matt@cyclops5.berkeley.edu (Matt Austern)
Newsgroups: comp.std.c++
Subject: Re: Q: Items in associative containers need == and < ?
Date: 01 Nov 1995 19:29:49 GMT
Organization: University of California at Berkeley (computational neuroscience)
Approved: matt@physics10.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Nov1112558@cyclops5.berkeley.edu>
References: <477o7e$5pd@info.uci.kun.nl>
Reply-To: matt@physics.berkeley.edu
NNTP-Posting-Host: physics10.berkeley.edu