apr*_*amc 3 c++ overload-resolution template-meta-programming c++17
#include <iostream>
struct A
{
void update(bool const & v)
{
std::cout << std::boolalpha << v << std::endl;
}
void update(std::string_view v)
{
std::cout << v << std::endl;
}
};
template <typename T>
void update(T const & item)
{
A a;
a.update(item);
}
int main()
{
const char * i = "string";
update(i);
}
Run Code Online (Sandbox Code Playgroud)
当我用a调用update时const char *,编译器使用bool参数而不是string_view?!调用函数。为什么??
从const char *到的转换std::string_view(通过的构造函数std::string_view)是用户定义的转换;在重载解析中,这比标准转换(从到的隐式转换)匹配差。const char*bool
1)标准转换序列总是比用户定义的转换序列或省略号转换序列更好。