From: David Abrahams (dave_at_[hidden])
Date: 2003-08-23 06:46:42
Daryle Walker <dwalker07_at_[hidden]> writes:
> On Thursday, August 21, 2003, at 10:12 PM, Beman Dawes wrote:
>> At 06:38 PM 8/21/2003, David Abrahams wrote:
>>> I need to make a mapping over paths. Is there any important reason
>>> there's no operator< provided?
>> I don't think it has been discussed. I've had the need myself, but
>> worked around it by using path::string() to generate the key.
>> There were a number of discussions about operator== and !=. They can
>> be subject to serious abuse and misunderstanding, and so are left
>> out. I'm still not sure if that was the right decision, so might be
>> willing to review it.
>> Anyhow, we should be able to support maps and sets of paths. I'll
>> try to give it some thought in the morning when I'm wider awake.
> If it isn't safe to even have the equality operators, then having the
> ordered inequality operators may not be safe either. If David has an
> ordering he wants to use in mind, then a custom comparison function
> object class can be made.
> I've seen quite a few requests for operator<() for class that don't
> have it (e.g. std::complex<>) just for the purpose of using it as an
> element type of an associative container. Forcing a type of have such
> an operator, even when it's inappropriate (i.e. the type doesn't
> suggest an overwhelmingly-natural ordering), defeats the purpose of
> the associative container class templates having comparator types in
> the first place!
But paths do have such an ordering. It's a lexicographic compare on
the conceptual underlying vector they contain. In other words
x.m_name < y.m_name
Unfortunately, that vector isn't available to clients of path so you
have to use x.string() < y.string(), which is only a poor substitute
for the actual vector.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk