How to create TypeTuple/ExpressionTuple from tuple/tuples

Kenji Hara k.hara.pg at gmail.com
Wed Aug 8 16:26:13 PDT 2012


On Tuesday, 7 August 2012 at 16:11:05 UTC, Andrej Mitrovic wrote:
> On 8/7/12, "Øivind" <oivind.loe at gmail.com> wrote:
>> How can I call this function with an already-constructed tuple
>> but pass the pule as an expressiontuple?
>>
>> auto v = tuple(1, 2, 3);
>> f(v);
>
> Use the .expand property:
> f(v.expand)

You can also use slice operator instead of expand property.


import std.stdio, std.typecons;
void f(T ...)(T t) {
     writeln(t.length);
}

void main(){
     auto v = tuple(1, 2, 3);
     f(v[]); // prints 3

     auto v0 = tuple(1, 2, 3);
     auto v1 = tuple(4, 5, 6);
     f(v0[], v1[]);  // prints 6
}



More information about the Digitalmars-d-learn mailing list