Named Arguments Status Update - Overloading by name
Walter Bright
newshound2 at digitalmars.com
Sun Jan 14 21:27:00 UTC 2024
On 1/11/2024 12:33 PM, Dennis wrote:
> On Thursday, 11 January 2024 at 19:21:46 UTC, Walter Bright wrote:
>> It's ok if the error is detected after instantiation. It can be detected by
>> testing to see if the mangled signature (which is generated for the type of
>> the function) already exists.
>
> That is the second option I listed in my opening post, which can be implemented
> easily.
> However, it would create a compile time 'race condition': the `f!short`
> instantiation which dmd sees first may succeed, but any subsequent attempts will
> fail.
>
> I don't know if this will result in inscrutable errors in practice, but it very
> well may.
string f(T)(T x) if (T.sizeof <= 2) { return "x"; }
string f(T)(T y) if (T.sizeof >= 2) { return "y"; }
Then the only thing to do is disallow an overload that differs only in the
parameter names.
More information about the Digitalmars-d
mailing list