From: Vladimir Grigoriev on

I wanted to say that for example for the std::find algorithm the requirement
of EqualityComparabality is not correctly or clear formulated because it is
not obligatory that typename std::iterator_traits<InputIterator>::value_type
is the same as T in the algorithm definition.:) In my example with Person an
object of the type Person is converted to size_t and size_t is
EqualityComparable indeed!

Vladimir Grigoriev



From: Vladimir Grigoriev on
So the resume is that the both forms of the algorithm std::find use a
predicate. Only the first form of the std::find uses a special predicate
which is written as an operator-function and as a result of such approach
there is no need to specify it as a parameter in the first form of
std::find.

Vladimir Grigoriev


From: sasha on
Duane Hebert wrote:
>
> I guess I don't understand what you mean by the STL algorithms using
> constructors. Can you give me an example of one that has to construct
> something?


What I meant to say of an algorithm needs to iterate over an array of
IDs, but there is no constructor that takes just an ID, then there is a
problem.
From: Ulrich Eckhardt on
Vladimir Grigoriev wrote:
> However try to provide that a + a will not compute when a + b, b + a, and
> b + b will compute for two classes when one is derived from another..

Simple, provide these three overloads and no others:

b operator+(a const& l, b const& r);
b operator+(b const& l, a const& r);
b operator+(b const& l, b const& r);

However, I can't think of a reason for this either. Think of this:

b some_b;
a& a_ref = some_b;
a_ref+a_ref; // now what?

struct c: b {...};
c some_c;
b& b_ref = some_c;
b_ref+b_ref; // and here?

Generally, operator+ is something that rather fits for value types. Public
inheritance usually means the type is rather an entity type, which don't
like being treated as a value.

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
Ulrich, I forgot to add that in the derived class the constructor for the
base class must be.

B( const A & );

In this case two conversions can be: B ==> A and A ==> B and an ambiguous
reference can occur.

Vladimir Grigoriev
..
"Ulrich Eckhardt" <eckhardt(a)satorlaser.com> wrote in message
news:i42037-u4l.ln1(a)satorlaser.homedns.org...
> Vladimir Grigoriev wrote:
>> However try to provide that a + a will not compute when a + b, b + a, and
>> b + b will compute for two classes when one is derived from another..
>
> Simple, provide these three overloads and no others:
>
> b operator+(a const& l, b const& r);
> b operator+(b const& l, a const& r);
> b operator+(b const& l, b const& r);
>
> However, I can't think of a reason for this either. Think of this:
>
> b some_b;
> a& a_ref = some_b;
> a_ref+a_ref; // now what?
>
> struct c: b {...};
> c some_c;
> b& b_ref = some_c;
> b_ref+b_ref; // and here?
>
> Generally, operator+ is something that rather fits for value types. Public
> inheritance usually means the type is rather an entity type, which don't
> like being treated as a value.
>
> Uli
>
> --
> C++ FAQ: http://parashift.com/c++-faq-lite
>
> Sator Laser GmbH
> Geschaftsfuhrer: Thorsten Focking, Amtsgericht Hamburg HR B62 932