non-typesafe variadic lazy arguments

Regan Heath regan at netmail.co.nz
Fri Feb 1 09:25:41 PST 2008


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);
}


More information about the Digitalmars-d-learn mailing list