Boost logo

Boost :

From: Bo Persson (bop_at_[hidden])
Date: 2006-07-13 17:40:38


"Sean Parent" <sparent_at_[hidden]> skrev i meddelandet
news:BC803577-3DC2-4D20-BB64-84E72A501CEB_at_adobe.com...
> Christoph Ludwig posted the correct reason why std::complex should
> not have an operator < () defined - sorry, my follow up using
> addition was poorly constructed.
>
> What I am proposing is that std::less should be defined for
> std::complex.

Disagree. That could potentially break other template programming
using std::less, to support std::unary_negate etc. Suddenly this would
"work" for std::complex, when it shouldn't.

> Why would we have a separate default relation for set/map then
> std::less? std::less is intended to map to operator <() on the type
> _or_ to a total ordering for the type if operator <() is not
> defined.

No, that's just for pointers. 20.5.7/8 says:

"For templates greater, less, greater_equal, and less_equal, the
specializations for any pointer type yield a total
order, even if the built-in operators <, >, <=, >= do not."

It doesn't mention std::complex or any other composite types.

> For pair<shared_ptr<>, int> - what makes shared_ptr special?

The fact that it is a pointer? I don't care much if it doesn't have an
ordering.

>
> std::less is supposed to be operator <, unless operator < is not
> defined in which case std::less provides a total ordering. It isn't
> ambiguous.

Where does the standard say that?

If you want to have an ordered collection of otherwise unordered data,
the relation must be an application specific attribute. So define an
appropriate functor, and use that with std::map, etc.

Bo Persson


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk