3
在研究时,我发现Why “transform(s.begin(),s.end(),s.begin(),tolower)” can't be complied successfully?,并且解决方案是使用::tolower
。作为一个练习,我想看看我是否可以禁用它(在区域设置头文件中)并且使用std::tolower
。首先,我们从简单的开始:禁用不必要的过载保护
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);
}
编译器不能推断正确的过载。所以我们提供char模板:
std::transform(chars.begin(), chars.end(), chars.begin(), std::tolower<char>);
所以我们又回到原点了。我知道这是未定义的行为,但我想我可以把它放到空间std:
namespace std {
template <typename charT> charT tolower(charT c, std::locale const& loc) = delete;
}
现在,编译器说,我重新定义的功能。
using std::tolower;
template <typename charT> charT tolower(charT c, std::locale const& loc) = delete;
也不起作用。
现在这是毫无意义的练习,但是这可能吗?
显式删除函数不会将其从重载解析中移除;这只意味着如果选择了超载,则会出现错误。 – 2014-12-03 14:23:36