non-typesafe variadic lazy arguments
Steven Schveighoffer
schveiguy at yahoo.com
Mon Feb 4 15:20:44 PST 2008
"Regan Heath" wrote
> Does this help:
>
> module lazy_any;
>
> import std.thread;
> import std.stdio;
> import std.c.time;
> import std.c.string;
> import std.string;
>
> void call(R, U...)(bool condition, R delegate(U) dg, U args)
> {
> if (condition)
> writefln(dg(args));
> }
>
> void main(string[] args)
> {
> string bob(int i, string s, float f)
> {
> return format("%s, %s, %s", i, s, f);
> }
>
> call(true, &bob, 1, "test1".idup, 5.2f);
> call(false, &bob, 2, "test2".idup, 6.3f);
> call(true, &bob, 3, "test3".idup, 7.4f);
> }
I definitely learned something here, but unfortunately, this doesn't solve
the problem. What I want is for the tuple to be converted to delegates just
like lazy converts arguments to delegates.
To demonstrate my issue, I think this would still evaluate f:
string f(string x, string y)
{
return x ~ y;
}
call(false, &bob, 1, f("test", "1"), 5.2f);
What I want is a way so that f("test", "1") is not evaluated unless needed.
-Steve
More information about the Digitalmars-d-learn
mailing list