Topic: std::equal question


Author: "Joe Gottman" <joegottman@worldnet.att.net>
Date: Thu, 4 Oct 2001 15:51:24 GMT
Raw View
The signature of the function std::equal is

template <class Iterator1, class Iterator2>
bool equal(Iterator1 first1, Iterator1 last1, Iterator1 first2)

It assumes that the range [first2, first2 + (last1 - first1)) is a valid
range, i.e. that the [first1, last1) is the smaller range.  This probably
saves some time, as the inner loop only needs to compare one pair of
iterators for equality.  But there are many cases where you might want to
test two ranges for equality and you don't know which one might be shorter.
Why doesn't this function take a fourth parameter, so you can test 2 ranges
of unknown size for equality?

Joe Gottman

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]