Generating members from parameter tuple

John Colvin john.loughran.colvin at gmail.com
Mon Aug 19 09:22:19 PDT 2013


On Monday, 19 August 2013 at 06:56:24 UTC, Brad Anderson wrote:
> import std.typetuple;
>
> struct S(T...)
> {
> 	alias Types = T;
> }
>
> alias Si = S!(int, short);
> alias Sf = S!(float, double);
>
> template STypes(STy) { alias STypes = STy.Types; }
>
>
> struct B(Ss...)
> {
> 	alias CombinedTypes =
> 		NoDuplicates!(TypeTuple!(staticMap!(STypes, Ss)));
> 	
> 	// I'd like to create a member here for every type in 
> CombinedTypes
> 	// that is an array of each type. e.g.,
> 	// int[] 	_intArray;
> 	// short[] 	_shortArray;
> 	// float[]	_floatArray;
> 	// double[]	_doubleArray;
> 	//
> 	// I don't believe the names matter because I'd probably want
> 	// to use a templated method that returns the appropriate
> 	// member based on the type supplied (e.g., getArray!int(),
> 	// getArray!short(), etc.)
> }

Take a look at the implementation of std.typetuple.Tuple, it does 
something similar.


More information about the Digitalmars-d-learn mailing list