Generating members from parameter tuple
Brad Anderson
eco at gnuk.net
Mon Aug 19 09:58:24 PDT 2013
On Monday, 19 August 2013 at 16:22:21 UTC, John Colvin wrote:
> 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.
I actually looked there first but it parses the types to support
named parameters so it was much more complicated than I could use.
More information about the Digitalmars-d-learn
mailing list