Variadic templates

Walter Bright newshound at digitalmars.com
Sat Nov 4 01:20:34 PST 2006


Lionello Lunesu wrote:
> Walter Bright wrote:
>> Knud Sørensen wrote:
>>> Will something like this be possible ??
>>>
>>> tuple t=(7, 'a', 6.8);
>>
>> Something like that.
>>
>>>  print at t; // for print(7, 'a', 6.8)
>>
>> It would be:
>>     print(t);
> 
> What about the comma operator? It would be perfect for creating tuples, 
> and very consistent with the way functions are called. For example 
> print(7,'a',6.8) passes to tuple (7,'a',6.8) to the function print.

For creating tuples, the following works:

template Tuple(T...)
{
     alias T Tuple;
}

alias Tuple!(7, 'a', 6.8) t;
print(t);



More information about the Digitalmars-d mailing list