non-typesafe variadic lazy arguments

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 5 05:52:05 PST 2008


"Steven Schveighoffer" wrote
> However, this does work:
>
> void call(R, U...)(bool condition, R delegate(U) dg, lazy U args)
> {
> if (condition)
> writefln(dg(args));
> }
>
> Thanks for the help Regan!!! :)
>
> -Steve

ugh! it almost works :)  The issue is with lazy args and string/array 
literals.

If you do this:

call(true, &bob, "hello");

The compiler complains because it can't create a delegate function that 
returns a char[5u].  Functions cannot return a static array, so this seems 
rather silly (i.e. if you are lazily evaluating a string constant, there is 
no penalty for returning a char[] instead of a char[5u]).  I'm going to file 
it as a bug, but if this gets fixed, everything will be good!

-Steve 




More information about the Digitalmars-d-learn mailing list