From: Vladimir Grigoriev on
Let consider an example.

There is a class named Person. And it has a member size_t personalID and an
equality operator

bool operator ==( const Person &lhs, size_t targetID );

However there is not a Person constructor with one argument equal to size_t
as a personal ID.
So there is the above equality operator and there is no a reverse equality
operator as

bool operator ==( size_t targetID, const Personal &rhs ); // invalid

Let assume further that some persons with personal IDs which belong to a
range of personal IDs (a simple array) have gotten a bonus. And we are going
to check which persons of some department are among them.

What should we to do? Shoot ourselves?
Our attempt to use the algorithm std::find_first_of is prohibited by the
Standard which requires equality comparability.
So main area of classes and objects are overboard of STD algorithms. At the
same time there is not something in the definition of find algorithms that
prevents to use them with classes which have an equality operator which does
not satisfies the requirements
if a == b then must be b == a

Vladimir Grigoriev



From: Victor Bazarov on
Vladimir Grigoriev wrote:
> Let consider an example.
>
> There is a class named Person. And it has a member size_t personalID and an
> equality operator
>
> bool operator ==( const Person &lhs, size_t targetID );
>
> However there is not a Person constructor with one argument equal to size_t
> as a personal ID.
> So there is the above equality operator and there is no a reverse equality
> operator as
>
> bool operator ==( size_t targetID, const Personal &rhs ); // invalid
>
> Let assume further that some persons with personal IDs which belong to a
> range of personal IDs (a simple array) have gotten a bonus. And we are going
> to check which persons of some department are among them.
> What should we to do? Shoot ourselves?
> Our attempt to use the algorithm std::find_first_of is prohibited by the
> Standard which requires equality comparability.

Huh? Define a predicate that will take size_t and Personal and use "the
other" version of 'find_first_of'.

> So main area of classes and objects are overboard of STD algorithms. At the
> same time there is not something in the definition of find algorithms that
> prevents to use them with classes which have an equality operator which does
> not satisfies the requirements
> if a == b then must be b == a

You seem to be genuinely concerned with Standard's deficiencies. That's
very commendable. Now, collect all your gripes, make sure you don't
miss anything (like this time, for instance), and then make your
suggestions how to improve the language and/or the library. Follow the
procedure for filing defect reports, post to 'comp.std.c++', in other
words join in on the fun. Then your complaining will look more like
constructive criticism rather than whining of somebody who hasn't
learned the language yet. No offence intended.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
From: Vladimir Grigoriev on

"Victor Bazarov" <v.Abazarov(a)comAcast.net> wrote in message
news:hj9je3$ll0$1(a)news.datemas.de...
> Vladimir Grigoriev wrote:
>> Let consider an example.
>>
>> There is a class named Person. And it has a member size_t personalID and
>> an equality operator
>>
>> bool operator ==( const Person &lhs, size_t targetID );
>>
>> However there is not a Person constructor with one argument equal to
>> size_t as a personal ID.
>> So there is the above equality operator and there is no a reverse
>> equality operator as
>>
>> bool operator ==( size_t targetID, const Personal &rhs ); // invalid
>>
>> Let assume further that some persons with personal IDs which belong to a
>> range of personal IDs (a simple array) have gotten a bonus. And we are
>> going to check which persons of some department are among them.
>> What should we to do? Shoot ourselves?
>> Our attempt to use the algorithm std::find_first_of is prohibited by the
>> Standard which requires equality comparability.
>
> Huh? Define a predicate that will take size_t and Personal and use "the
> other" version of 'find_first_of'.
>

Victor, what predicate should I build instead of already existent equality
operator? In fact I must take for example as an alternative of the equality
operator the std::equal_to functor and change it such a way that nobody
even could notice that I am using the same equality operator instead of
using the equality operator directly. I do not see a great sense in this.

Vladimir Grigoriev


From: Vladimir Grigoriev on

Victor it is funny that only now after your response I have seen that the
requirement
"Type T is EquallyComparable" exist only in the comments for the std::find
algorithm. Al other find algorithms (find_end, find_first_of) have no this
phrase in their comments. Is this requirement applicable to all find
algorithms or only for the first one?

Vladimir Grigoriev



From: Ulrich Eckhardt on
Note up front: There are comp.lang.c++.moderated and comp.lang.std.c++
(IIRC) where standard defects are better taken care of. Bitching and
moaning about a standard and that others follow or even enforce the
standard is IMHO just noise _here_.

Vladimir Grigoriev wrote:
> There is a class named Person. And it has a member size_t personalID and
> an equality operator
>
> bool operator ==( const Person &lhs, size_t targetID );
>
> However there is not a Person constructor with one argument equal to
> size_t as a personal ID.
> So there is the above equality operator and there is no a reverse equality
> operator as
>
> bool operator ==( size_t targetID, const Personal &rhs ); // invalid

I find that already questionable, I wouldn't overload operator== for that.
Why not overload comparison with a std::string to compare the name? And the
same again, to compare the address, etc. etc. etc.

> Let assume further that some persons with personal IDs which belong
> to a range of personal IDs (a simple array) have gotten a bonus. And
> we are going to check which persons of some department are among them.
>
> What should we to do? Shoot ourselves?

Invoke std::find_if in a loop:

iterator it = begin;
while(true) {
it=find_if(begin, end, <predicate>);
if(it==end)
break;
it->give_raise();
++it;
}

> Our attempt to use the algorithm std::find_first_of is prohibited by the
> Standard which requires equality comparability. So main area of classes
> and objects are overboard of STD algorithms.

*sigh* No, you just need to learn how to use them. And yes, sometimes that
requires writing some code.

Uli

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

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932