Originally Posted by
Elysia
Perhaps it is, but they should both do the same thing (if the algorithm is used in such a way) and the to_lower member is simply less to type and therefore preferred (also less error prone).
I would like to point out that the free function to_lower requires you to type one character less than the member function string::to_lower (or generally any free function vs member function), namely the dot character.
Now, if an API provided a key_exists function for containers with find member, exactly how does the following not abstract the algorithm away for the user less than a member function of set, map etc. would?
Code:
template <class Container, class Type>
bool key_exists(const Container& c, const Type& t)
{
return c.find(t) != c.end();
}
Edit:
Free functions are simple "worse" (if you could call it that), because it's exactly that - free. It's not a member function.
Yeah, in Western society the word "free" has clearly negative connotations. Anybody should see immediately that free things are bad.