correct way to create boiler plate code

Trass3r un at known.com
Mon May 16 12:58:20 PDT 2011


> foreach runs at runtime, while mixin is expanded at compile time.

Not the whole truth though.

foreach over tuples gets unrolled at compile time so you can do stuff like:

// +=, -=, ...
Vector opOpAssign(string op, U)(U s)
{
	foreach (i, _; tuple)
		mixin("tuple[i] " ~ op ~ "= s;");
	return this;
}


More information about the Digitalmars-d-learn mailing list