Proposal: overload conflict resolution

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sun Dec 10 10:41:19 PST 2006


Rioshin an'Harthen wrote:
> "Frits van Bommel" <fvbommel at REMwOVExCAPSs.nl> wrote:
>> Chris Miller wrote:
>>> Strange example:
>>>    void bar(default char[] s, int x);
>>>    void bar(char[] s, default long x);
>> I like the basic idea, but maybe it gets a bit to hairy when multiple 
>> parameters can have this attribute...
>>
>> Maybe it should be an attribute of the function instead?
>> Then it becomes quite clear, I think: if there are multiple equally-good 
>> matches and among them the number of overloads with the attribute is 
>> anything other than one (that is, none or at least two) it's still an 
>> error, otherwise the one declared 'default' is picked.
> 
> So, we'd have something like
> 
> default void foo(char[] s);
> void foo(wchar[] s);
> void foo(dchar[] s);
> 
> with only one function of the same name at most with default...

I see no reason why you can't declare multiple 'default's, as long as 
you make sure they don't conflict. Basically, only one would be allowed 
in the overload set without it being an error.

For instance:
/// UTF conversion
default char[] toString(char[]);
char[] toString(wchar[]);		/// ditto
char[] toString(wchar[]);		/// ditto

/// Converts a number to a printable representation
default char[] toString(int);
char[] toString(uint);		/// ditto

I don't think these will conflict.
Now, which one of the latter two to make the default, that's another 
question... (I just arbitrarily picked one)

> I like this :). Votes++ for this modification.



More information about the Digitalmars-d mailing list