While researching, I found Why “transform(s.begin(),s.end(),s.begin(),tolower)” can't be complied successfully? , and the solution is to use ::tolower
. As an exercise, I want to see if I can disable that (in locale header file) overload and use std::tolower
. First, we start simple:
template <typename charT> charT tolower(charT c, std::locale const& loc) = delete;
int main()
{
std::vector<char> chars = { 'a', 'D', 'c', 'b' };
std::transform(chars.begin(), chars.end(), chars.begin(), std::tolower);
}
The compiler cannot deduce the correct overload. So we provide the char template:
std::transform(chars.begin(), chars.end(), chars.begin(), std::tolower<char>);
So we're back to square one. I know it is undefined behavior, but I thought I could put it into namespace std:
namespace std {
template <typename charT> charT tolower(charT c, std::locale const& loc) = delete;
}
Now the compiler says I'm redefining the function.
using std::tolower;
template <typename charT> charT tolower(charT c, std::locale const& loc) = delete;
doesn't work either.
Now this is pointless exercise, but is this possible?