|
Boost : |
From: Gavin Lambert (boost_at_[hidden])
Date: 2023-02-20 05:39:51
On 20/02/2023 18:25, Peter Dimov wrote:
> Defining "unprincipled" operator== overloads is common practice, typically
> such that x == y means x.something( y ). E.g.
>
> struct none {};
>
> class X
> {
> private:
>
> int id_ = 0;
>
> public:
>
> explicit X( int id, ... );
>
> bool operator==( int id ) const noexcept { return id_ == id; }
> bool operator==( none ) const noexcept { return id_ == 0; }
> };
>
> or the already mentioned boost::function, which uses it to mean "contains".
> Whatever your definition of equivalence, X is neither equivalent to an int,
> nor to a 'none', and 'none' doesn't even have operator==.
I fail to see how that breaks commutability, or is incompatible with the
C++20 changes, however. It just means it becomes legal to write `none{}
== X{5}` when before you might have been forced to write `X{5} ==
none{}` if the author of X didn't implement the reverse operator.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk