Re: Using std::equal with an empty set.
Vladimir Grigoriev wrote:
I have pointed out already why the algorithm must return false. It must
return false because the statement 'Otherwise' is true. The true is
returned in only one case when "for every iterator i in the range
[first1, last1) the following corresponding conditions hold.."'. Are
you have at least one iterator which satisfies the conditions? No,
you have not. If I cannot even check the conditions why the
algorithm should return true?! For this case there is the phrase
"Otherwise returns false".
Please stop. Sorry, but if you knew anything at all about the STL, where
these algorithms come from, you wouldn't be surprised about this. Take a
look at [1], it say there very explicitly, though technically redundantly,
that it compares two ranges.
Now, where is the second range? There is just one iterator after all! Simple
answer, the second range is assumed to have the same length as the first,
even though no past-the-end iterator is supplied. One result of this is
that if the first sequence is empty, the second one is empty, too, and they
are alway equal. Someone posted a link here already which even gives this
principle a name.
BTW: If the range starting at the second iterator is shorter, you get
undefined behaviour. If it is longer, only a subset is compared.
Now, if you want to say that the wording in the standard can be improved,
then say so. Preferably do so to people that care, you were given direction
elsethreads. But, please stop making those nonsense claims that comparison
of two empty sequences should return false and stop wasting everyone's
time.
Seriously, I'm wondering if you're not just an elaborated troll.
Uli
[1] http://www.sgi.com/tech/stl/equal.html
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Thorsten F??cking, Amtsgericht Hamburg HR B62 932