Boost logo

Boost :

Subject: Re: [boost] Boost.Algorithm design question
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-11-01 13:28:56

Andrew Sutton wrote:

> It should not. Equality should mean equality. I don't see why this
> should be so distasteful.

First, unnecessarily requiring both sides to be of the same type causes
problems with (for instance)

signed char c1 = -1;
unsigned char c2 = 0xFF;

where c1 != c2, but they compare equal if either is converted to the type of
the other. So this requirement leads to much extra complexity with
common_type and so on.


"test" == std::string( "test" ) == "test"

but "test" may well not compare equal to "test".

Third, because of the preceding two points, std::find does not, in practice,
require same type or equivalence. This leads people to use it with types of
the form

struct X
    int key_;
    ... value_;

    bool operator==( int key ) const { return key_ == key; }

Now... this is where you legitimately may claim that these people are wrong.
But I don't see why we need to prohibit this code. It makes no intuitive
sense to me for std::find( first, last, value ) to differ from
std::find_if( first, last, _1 == value ).

Boost list run by bdawes at, gregod at, cpdaniel at, john at