Problems with Template codegen

Derek Parnell derek at nomail.afraid.org
Sun Feb 4 18:44:12 PST 2007


On Sun, 04 Feb 2007 16:50:02 -0800, kris wrote:

> At this time, D templates are a bit finicky when it comes to argument 
> matching -- IFTI matching, to be explicit. For example:
> 
> # uint locate(T) (T[] source, T match, uint start=0);
> #
> # locate ("wumpus", 'p', 1);
> 
> will not compile because '1' is an integer literal, and does not match 
> the template parameter 'uint'.

The way I'd prefer D to work is rather than seeing the 1 and deciding that
this literal must only be an *int*, it could recognize that the literal *1*
is ambiguous, as it could be stored as one of a number of integer forms. It
would then search for which signatures match "integer" rather than "int",
and if there is only one, resolve the literal's ambiguity by using the sole
matching signature. Of course, if there are multiple matching signatures
then it needs to alert the coder of the ambiguity and have them sort it out
by explicit casts.

I base my opinion on the need for programming languages and compilers to be
helpful to people, as a first priority.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
5/02/2007 1:37:33 PM



More information about the Digitalmars-d mailing list