How is it possible that this code below with conversion from std::string_view to std::string compiles:
struct S {
std::string str;
S(std::string_view str_view) : str{ str_view } { }
};
but this one does not compile?
void foo(std::string) { }
int main() {
std::string_view str_view{ "text" };
foo(str_view);
}
The second one gives an error: cannot convert argument 1 from std::string_view to std::string and no sutiable user-defined conversion from std::string_view to std::string exists.
How should I call foo() properly?