Hi Gavin,
On 26 Jan 2017, at 23:28, Gavin Lambert
wrote: On 27/01/2017 03:04, Hans Dembinski wrote:
You don't know why the user added the overloads for foo, perhaps she suddenly had to adapt foo so that it also works with C code which uses a lot of const char*. As a designer, you have no control over other peoples' interfaces.
That wouldn't be a problem, because no sane implicit conversion could ever return const char*. And even if std::string had its own conversion (which it doesn't), the compiler won't chain two implicit conversions, so it can't be ambiguous.
It was just an example to illustrate the general danger of implicit casts.
The only other one that seems more likely is if the factories could output std::wstring as well as std::string, since it's reasonable that user code would have overloads for both (or accept basic_string). In practice though I don't think even this would be a problem, as:
std::string x = concat("foo", "bar"); std::wstring y = concat(L"foo", L"bar"); std::wstring z = concat("foo", bar");
So let's say concat returns a factory with implicit casts to std::string and std::wstring. And I have function foo(…) which accepts std::string and std::wstring. Now if I write foo(concat(42)) I get an ambiguity again. Hans