Background: While studying chapter 16 page 808 of C++ Primer 5th edition I found two type of compare function.
template <typename T> int compare(const T& v1, const T& v2)
{
if (v1 < v2) return -1;
if (v2 < v1) return 1;
return 0;
}
template <typename T> int compare(const T &v1, const T &v2)
{
if (less<T>()(v1, v2)) return -1;
if (less<T>()(v2, v1)) return 1;
return 0;
}
The problem with our original version is that if a user calls it with two pointers and those pointers do not point to the same array, then our code is undefined.
This above line is not clear to me.
Can anyone explain this above line?