#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);
}
when I call update with a const char *
, compiler calls the function with bool
argument instead of string_view
?! why ??!
The conversion from const char *
to std::string_view
(via the constructor of std::string_view
) is a user-defined conversion; which is a worse match than the standard conversion (the implicit conversion from const char*
to bool
) in overload resolution.
1) A standard conversion sequence is always better than a user-defined conversion sequence or an ellipsis conversion sequence.