Am 21.05.24 um 13:20 schrieb Markus Schaaf:
Am 17.05.24 um 17:25 schrieb Marcel Mueller:
How to force the last overload with fixed size char arrays?
As far as I know, it is impossible. If you think about it, you may not
want such an overload anyway. Use string_view or a custom class like it,
and avoid plain (char const *).
In fact I have done this now - see my answer to Bonita.
There is only one drawback. The additional conversion prevents some
other assignments that itself used some kind of conversion like
(operator const char*).
From my point of view the decay from an array to a pointer type is pure
pain that should never had made it into C++. But changing this would
break zillions of existing code. :-(
Maybe a function parameter should be declarable as "explicit" to forbid
such decay:
type& operator=(explicit const char* str);
int foo(int x, explicit int y); // does not bind long to y
Just an idea.
Something similar has been introduced with the option to explicitly
delete some unwanted overloads. But this does not cover this use case
because the decay to a pointer takes precedence over template overloads.
Marcel
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)