C++ like 'string' transform ...
Posted on 05 Apr 2009 under c, coding .
All we need is a naked class with the () operator overloaded to execute and wrap the "real" tolower.
struct toLower
{
int operator()(int ch)
{
return tolower(ch);
};
};
With this our transform will resume to this beautiful and elegant line ...
transform( s.begin(), s.end(), s.begin(), toLower() );
... instead of the very 'C like' looking (even if we used C++ like casting):
transform( s.begin(), s.end(), s.begin(), (int(*)(int))tolower );
Pretty, pretty :D




