Compile-time optimization

JS js.mdnq at gmail.com
Fri Jul 26 06:26:49 PDT 2013


The following code works better. Forgot to allow for multiple 
arguments. Runtime variables are not unrolled though but I'll 
work on understanding how you were able to unify the two as one(I 
think in your reduceImpl).

module main;

import std.stdio, std.traits;

template tuple(args...)
{
     alias tuple = args;
}

template tUnrollArgs(args...)
{
	static if (isArray!(typeof(args[0])))
	{
		pragma(msg, "isarray");
		static if (args.length > 1)
		{
			pragma(msg, "unrolling");
			alias tUnrollArgs = tuple!(tUnrollArgs!(args[0]), args[1..$]);
		}
		else
		{
			static if (args[0].length > 1)
			{
				pragma(msg, "1");
				alias tUnrollArgs = tuple!(args[0][0], 
tUnrollArgs!(args[0][1..$]));
			}
			else
			{
				pragma(msg, "2");
				alias tUnrollArgs = tuple!(args[0][0]);
			}
		}
	}
	else
		static if (args[0].length > 1)
			alias tUnrollArgs = tuple!(args[0], 
tUnrollArgs!(args[0][1..$]));
		else
			alias tUnrollArgs = args;
}

void main(string[] argv)
{
	auto z = ["1", "2"];
     writeln(tUnrollArgs!(["a", "b"], z, "c"));
	readln();
}




More information about the Digitalmars-d mailing list