Boost logo

Boost :

Subject: Re: [boost] Boost.Algorithm design question
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-10-07 17:20:17


Dave Abrahams wrote:
> on Fri Oct 07 2011, "Peter Dimov" <pdimov-AT-pdimov.com> wrote:
...
> > The current specification (ignoring the conversion issue for now, as
> > it's separate) says:
> >
> > - when T is EqualityComparable, returns the first element that equals
> > value;
> > - otherwise, returns the first element *i for which *i == value.
> >
> > Your preferred replacement says:
> >
> > - when T is EqualityComparable, returns the first element that equals
> > value;
> > - otherwise, the behavior is undefined.
> >
> > Do tell me why it's better.
>
> Well, if you phrase it that way, it's a little different. The original
> description only had the "otherwise" clause, right?

Yes. The "otherwise" clause implies the preceding clause when T is
EqualityComparable. I wrote it that way to highlight the fact that the two
specifications only differ in the "otherwise" part.

> The "replacement" is still simpler, because you wouldn't actually write
> the "otherwise ..." clause; you just say it requires EqualityComparable.

It may be simpler, but why is it better? People who operate on properly
EqualityComparable types see no difference between the two, whereas people
whose op== isn't, for some unfathomable reason, an equivalence relation
still get the expected result from the first and undefined behavior from the
second.


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