I just wrote some code to test the behavior of std::equal, and came away surprised:
if(!std::equal(lst1.begin(), lst1.end(), lst2.begin()))
throw std::logic_error("Error: 2 empty lists should always be equal");
if(std::equal(lst1.begin(), lst1.end(), lst2.begin()))
throw std::logic_error("Error: comparing 2 lists where one is not empty should not be equal");
std::cerr << e.what();
Error: comparing 2 lists where one is not empty should not be equal
Observation: why is it the std::equal does not first check if the 2 containers have the same size() ? Was there a legitimate reason?
How? You do do not pass containers to the function, you pass in iterators. The function has no way of knowing the size of the second container. All it can do is assume bona fide that the user passed in two valid container ranges (i.e. that the second range is correctly specified as the half-open interval [
lst1.end()[) and act accordingly.