Passing a single tuple or multiple values

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 19 08:36:42 PDT 2016


On Tuesday, 19 July 2016 at 13:33:41 UTC, jmh530 wrote:
> On Tuesday, 19 July 2016 at 07:23:52 UTC, John wrote:
>>
>> auto bar(T...)(T x)
>> {
>>   static if (T.length == 1 && isTuple!(T[0]))
>>     return foo(x.expand);
>>   else
>>     return foo(x);
>> }
>>
>
> Hmm, this actually doesn't seem to be resolving my issue. I'm 
> still getting the error about not being able to expand x.
>
> I tried it like below and got the same error.
>
> auto bar(T...)(T x)
> {
> 	static if (T.length > 1)
> 	{
> 		return foo(x);
> 	}
> 	else static if (T.length == 1 && isTuple!(T))
> 	{
> 		return foo(x.expand);
> 	}
> }

As you have to do `isTuple!(T[0])`, you also have to do 
`x[0].expand`.
That's because T... works "as if" it was an array of types, and 
x, being of type T, it works "as if" it was an array of values. 
So you have to use an index in both cases.


More information about the Digitalmars-d-learn mailing list