From: Ulrich Eckhardt on
Vladimir Grigoriev wrote:
> There is no a great sense to compare some size_t value with an object of
> type Person. This comparison has no sense. It is a general situation when
> converting some object of a class to an integral type has sense while
> converting an integral type to an object has no sense. For this purpose
> the explicit reywoard was introduced. The same is valid for operators.
> i.e. sometimes a op b has sense while b op a has no sense.

I'd say whether switching operands still has sense depends on the operator.
For an equality comparison, I expect it to be fully commutative. Similarly
for inequality, while e.g. greater behaves slightly different.

Are you really implying that a==b makes sense when b==a doesn't? I already
voiced my opinion on comparison of a person with an ID: "I wouldn't
overload operator== for that."

Uli

--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: Vladimir Grigoriev on
There are situations when A is a subset of B and in this case you may apply
some relation or comparison operator showing that A is a subset of B.
However you may not state that B is a subset of A. So a reverse relation is
absent and consequently reverse operators also are absent.
For example you can define a Point class derived from std::pair. And your
Point class may have arithmetic operators. You may to add a std::pair object
to a Point object but your may not add a Point object to a std:pair object.
Otherwise std::pair class will have a feature which was not supposed to be.
The same situation can be with relation operators.

Vladimir Grigoriev

"Ulrich Eckhardt" <eckhardt(a)satorlaser.com> wrote in message
news:5acm27-40c.ln1(a)satorlaser.homedns.org...
> Are you really implying that a==b makes sense when b==a doesn't? I already
> voiced my opinion on comparison of a person with an ID: "I wouldn't
> overload operator== for that."
>
> Uli
>
> --
> C++ FAQ: http://parashift.com/c++-faq-lite
>
> Sator Laser GmbH
> Geschaftsfuhrer: Thorsten Focking, Amtsgericht Hamburg HR B62 932


From: Vladimir Grigoriev on
The problem is the same as with std::min and std::min_element. I do not see
any reasonable explanation why these restrictions were adopted. It seems
that this shrinks functionality of C++ without any serious reason.
For example all that I have heard here relative to std::min is some
references to sort algorithms. However I do not see a relation between
std::min and sort algorithms..

Vladimir Grigoriev

"Ulrich Eckhardt" <eckhardt(a)satorlaser.com> wrote in message
news:5acm27-40c.ln1(a)satorlaser.homedns.org...
> Vladimir Grigoriev wrote:
>> There is no a great sense to compare some size_t value with an object of
>> type Person. This comparison has no sense. It is a general situation when
>> converting some object of a class to an integral type has sense while
>> converting an integral type to an object has no sense. For this purpose
>> the explicit reywoard was introduced. The same is valid for operators.
>> i.e. sometimes a op b has sense while b op a has no sense.
>
> I'd say whether switching operands still has sense depends on the
> operator.
> For an equality comparison, I expect it to be fully commutative. Similarly
> for inequality, while e.g. greater behaves slightly different.
>
> Are you really implying that a==b makes sense when b==a doesn't? I already
> voiced my opinion on comparison of a person with an ID: "I wouldn't
> overload operator== for that."
>
> Uli
>
> --
> C++ FAQ: http://parashift.com/c++-faq-lite
>
> Sator Laser GmbH
> Geschaftsfuhrer: Thorsten Focking, Amtsgericht Hamburg HR B62 932


From: sasha on
Duane Hebert wrote:
>

>
> What has the ctor for your class to do with the == operator for your class?
> Maybe I'm missing someting...
>
>

It may need to be constructed before compared - like when OP said during
iteration of an array of IDs.
From: Duane Hebert on

"sasha" <abc(a)fox.net> wrote in message news:O49e7$smKHA.6096(a)TK2MSFTNGP02.phx.gbl...
> Duane Hebert wrote:
>>
>
>>
>> What has the ctor for your class to do with the == operator for your class?
>> Maybe I'm missing someting...
>>
>>
>
> It may need to be constructed before compared - like when OP said during
> iteration of an array of IDs.

But if I have a ctor taking int, string and another taking string,int how does it relate to the
== operator? This compares instances of an object that has already been constructed.
I can have 27 ctors for a class and only one == operator.