i wanted to ask what differences there are between this userdefined equal bool
1 2 3 4 5 6 7 8 9
bool equal(const string& a, const string& b)
{
if (a.size() != b.size())
returnfalse;
for (size_t i = 0; i < a.size(); ++i)
if (toupper(a[i]) != toupper(b[i]))
returnfalse;
returntrue;
}
and the equal command with the <algorithm> include.
2. how to use the equal command in algorithm? in this userdefined i use it like this:
Your user-defined function will test for equality regardless of case (upper or lower).
The standard algorithm will see "YES" and "yes" as different. In this respect, your user-defined function will probably do what you want.
If you want to use std::equal as in <algorithm> you will need to use the form with a predicate, which will return the test for equality regardless of case.
I wouldn't deliberately name a user-defined function the same as one in the standard library, especially if they did different things.