Function parameters from TypeTuple

Tofu Ninja via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 17 10:57:57 PDT 2014


On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote:

Not sure if what I wrote made sense, instead I will just post the 
code that is vomiting on me...

template arrayType(T)
{
	alias arrayType = T[];
}

template multiAccess(Args ...)
{
	auto multiAccess(int i, staticMap!(arrayType, Args) args)
	{
		static if(args.length == 1) return Tuple!(args[0][i]);
		else return Tuple!(args[0][i], multiAccess!(Args[1 .. 
$])(args[1 .. $]));
	}
}

void main(string[] args)
{
	int[] a = [1,2];
	int[] b = [5,6];
	writeln(multiAccess!(int,int)(1, a,b));
}

but the compiler really does not like that at all... the error 
message are very unhelpful as well...

Generates 18 errors...

main.d(52): Error: variable _param_1 cannot be read at compile 
time
main.d(53): Error: variable _param_1 cannot be read at compile 
time
main.d(52): Error: variable _param_1 cannot be read at compile 
time
main.d(53): Error: variable _param_1 cannot be read at compile 
time
main.d(52): Error: tuple index 0 exceeds length 0
main.d(52): Error: tuple index 0 exceeds 0
main.d(52): Error: tuple index 0 exceeds length 0
main.d(52): Error: tuple index 0 exceeds 0
main.d(52): Error: tuple index 0 exceeds 0
main.d(53): Error: tuple index 0 exceeds length 0
main.d(53): Error: tuple index 0 exceeds 0
main.d(53): Error: tuple index 0 exceeds length 0
main.d(53): Error: tuple index 0 exceeds 0
main.d(53): Error: tuple index 0 exceeds 0
main.d(53): Error: slice [1..0] is out of range of [0..0]
main.d(53): Error: template instance main.multiAccess!() error 
instantiating
main.d(53):        instantiated from here: multiAccess!int
main.d(25):        instantiated from here: multiAccess!(int, int)
main.d(53): Error: template instance main.multiAccess!int error 
instantiating
main.d(25):        instantiated from here: multiAccess!(int, int)
main.d(25): Error: template instance main.multiAccess!(int, int) 
error instantiating


More information about the Digitalmars-d-learn mailing list