Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

::tolower vs std::tolower difference [duplicate]

I have

using namespace std;
vector<char> tmp;
tmp.push_back(val);
...

Now when I try

transform(tmp.begin(), tmp.end(), tmp.begin(), std::tolower);

It fails to compile, but this compiles:

transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);

What's the problem with std::tolower? It works with one argument, e.g., std::tolower(56) compiles. Thanks!

like image 889
hovnatan Avatar asked Jul 23 '15 14:07

hovnatan


1 Answers

std::tolower has two overloads and it cannot be resolved for the UnaryOperation where the C version ::tolower does not.

If you want to use the std::tolower you can use a lambda as

transform(tmp.begin(), tmp.end(), tmp.begin(), [](unsigned char c) {return std::tolower(c); });
like image 179
NathanOliver Avatar answered Oct 19 '22 08:10

NathanOliver