|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-05-24 12:36:25
From: "Darin Adler" <darin_at_[hidden]>
> On Thursday, May 24, 2001, at 07:01 AM, Peter Dimov wrote:
>
> > I have some comments on shared_ptr.
> >
> > 1. Isn't specializing std::less without defining the corresponding
> > operator<
> > setting a dangerous precedent? This means that sort(f, l) and sort(f, l,
> > less<>()) could potentially give different results.
>
> No, I don't think it's setting a precedent.
>
> C++ pointers themselves have a slightly more severe version of the same
> problem. Calls to sort (f, l), and sort (f, l, less<>()) can give
> different results for an array of pointers, for example.
Yes. Is continuing this 'tradition' with shared_ptr necessary? We can't
redefine operator< for pointers, but we can decide whether to provide
operator< or std::less for shared_ptr.
> 2) It doesn't provide the < operator. Thus sort (f, l) will fail to
> compile rather than relying on unspecified behavior. I think this is good
> and helps people write portable code.
I didn't suggest relying on unspecified behavior.
> An alternative choice would be to define the < operator and the other
> comparison operators too, being sure to use std::less on the underlying
> pointer rather than using the < operator. But I don't think this would be
> an improvement.
Why?
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk