From: Vladimir Grigoriev on
What should return the std::equal in case when [first, last) is an empty
set, true or false?

Vladimir Grigoriev


From: Igor Tandetnik on
Vladimir Grigoriev wrote:
> What should return the std::equal in case when [first, last) is an empty
> set, true or false?

true
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Vladimir Grigoriev on
From mathematical point of view an empty set is a subset of any set indeed.
However if to follow the Standard description it seems that in this case
std::equal must return false. Because according to the Standard the
following for example condition must hold

pred( *i, *( first2 + ( i - first1 ) ) )

As this condition does not hold for any itearator from [first, last) why
should std::equal return true?

Vladimir Grigoriev


"Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message
news:ecko8jbnKHA.4752(a)TK2MSFTNGP04.phx.gbl...
Vladimir Grigoriev wrote:
> What should return the std::equal in case when [first, last) is an empty
> set, true or false?

true
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily
a good idea. It is hard to be sure where they are going to land, and it
could be dangerous sitting under them as they fly overhead. -- RFC 1925


From: Ulrich Eckhardt on
Vladimir Grigoriev wrote:
> From mathematical point of view an empty set is a subset of any set
> indeed. However if to follow the Standard description it seems that in
> this case std::equal must return false. Because according to the
> Standard the following for example condition must hold
>
> pred( *i, *( first2 + ( i - first1 ) ) )
>
> As this condition does not hold for any itearator from [first, last) why
> should std::equal return true?

Actually, that condition holds for all elements in that range. Note that
there are effectively no dereferenceable iterators in that range because
first==last, hence also no elements. Note that the STL docs are probably
more explicit there, they are talking about two subsets of equal length
that are compared.

BTW, since you seem to look for thing you can flag as ambiguous (is it a
crusade you're on, btw?), also consider that string("abc").find("") returns
zero. ;)

Good luck!

Uli

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

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: Igor Tandetnik on
Vladimir Grigoriev wrote:
> From mathematical point of view an empty set is a subset of any set indeed.
> However if to follow the Standard description it seems that in this case
> std::equal must return false. Because according to the Standard the
> following for example condition must hold
>
> pred( *i, *( first2 + ( i - first1 ) ) )

It must hold for every iterator in the range [first, last). If there are no such iterators, then indeed the condition trivially holds for all of them. See also

http://en.wikipedia.org/wiki/Vacuous_truth

This is standard fare in predicate logic.

> As this condition does not hold for any itearator from [first, last)

You are committing a logical fallacy. The negation of "for all iterators in the range, the condition holds" is not "for all iterators in the range, the condition doesn't hold". It is "there exists an iterator in the range for which the condition doesn't hold". This last statement is obviously false when the range is empty, so the first statement must be true.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
 |  Next  |  Last
Pages: 1 2 3
Prev: Bounded Buffers
Next: Operator new