www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using template typetuples?

reply Sean Eskapp <eatingstaples gmail.com> writes:
The language documentation covers some basic uses of TypeTuples in templates,
but nothing about using them with classes. I would like a template class,
which essentially wraps a function, which has template parameters for return
value and template tuple arguments.

However, what if I want to convert a TypeTuple of int, double, string to its
respective Function-wrapped TypeTuple, i.e. Function!int, Function!double,
Function!string. Is there any way to do so?
Jan 12 2011
parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Sean Eskapp <eatingstaples gmail.com> wrote:

 The language documentation covers some basic uses of TypeTuples in  
 templates,
 but nothing about using them with classes. I would like a template class,
 which essentially wraps a function, which has template parameters for  
 return
 value and template tuple arguments.

 However, what if I want to convert a TypeTuple of int, double, string to  
 its
 respective Function-wrapped TypeTuple, i.e. Function!int,  
 Function!double,
 Function!string. Is there any way to do so?

std.typetuple has staticMap, which sounds like what you want: alias TypeTuple!( int, double, string ) tup; alias staticMap!( Function, tup ) functions; Is this what you want? -- Simen
Jan 12 2011
parent reply Sean Eskapp <eatingstaples gmail.com> writes:
That looks like it.. only, it's not working:

void main()
{
	TypeTuple!(int, int) foo;
	foo[0] = 1;
	foo[1] = 2;

	double MakeStuff(in int bar)
	{
		return cast(double)bar;
	}

	auto foobar = staticMap!(MakeStuff)(foo);
}

This fails compilation with the error "Error: function expected before (), not
()
of type ()"
Jan 12 2011
parent Sean Eskapp <eatingstaples gmail.com> writes:
Nevermind, I see my error.
Thank you!
Jan 12 2011