Proposal: overload conflict resolution

Derek Parnell derek at nomail.afraid.org
Mon Dec 11 14:29:55 PST 2006


On Mon, 11 Dec 2006 16:07:39 -0500, Pragma wrote:

>> Chris Miller wrote:
>>> Given the following function prototypes:
>>>    void foo(char[] s);
>>>    void foo(wchar[] s);
>>>    void foo(dchar[] s);
>>>
>>> Currently, if you try to do foo("hello"), the compiler will complain 
>>> because string literals simulteneous match all the above types.

...

> Still, I've often wondered if there wasn't a better way.

Would it be possible for the compiler to encode an unqualified string
literal based on a hierarchy of matches. In other words, if there exists a
char[] match use that, otherwise if there exists a wchar[] match then use
that, otherwise if there exists a dchar[] match use that else there is no
match.

In Chris' original example the 'foo(char[])' would match and so the
compiler encodes the literal as utf-8. 

Thus is multiple matches are possible, the compiler chooses them in order
of utf-8, utf-16, and utf-32. Thus if the coder explicitly wants a specific
'foo' to be called they would need to explicitly encode the literal with
the c/w/d qualifier.

This idea seems reasonable and maybe also can be extended in concept to
unqualified numeric literals.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
12/12/2006 9:19:36 AM



More information about the Digitalmars-d mailing list