Variadic templates

BCS BCS at pathlink.com
Thu Nov 2 09:12:56 PST 2006


Walter Bright wrote:
> See http://www.digitalmars.com/d/variadic-function-templates.html
> 
> Why now? Because it's such a pain to do template programming without 
> them, and because I wanted to have a good signals and slots 
> implementation. That was the last piece needed to make S&S work right 
> (unless I'm way off track with it).
> 
> There's a lot of unexplored territory with the tuples, they should be 
> able to do a lot more than the current rather limited ability.

Ooohhh! Wow! Neat stuff! Tuples look cool, particularly with the 
"static" foreach on them. Is there any way to convert a struct/class 
into a tuple? It would allow something like this:


// byte swap every member of each argument


template ByteSwap(T, A...)
{
	void ByteSwap(inout T t, inout A a)
	{
		ByteSwap(t);
		foreach(t; a)
			ByteSwap(t);
	}
}

template ByteSwap(A)
{
	void ByteSwap(inout A a)
	{
		static if(is(a : Object))
			// form tuple from members
			ByteSwap(a[0].*);
		else
			LowLevelByteSwap(a[0].*);
	}
}



More information about the Digitalmars-d mailing list