Passing Elements of A Static Array as Function Parameters

Per Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 14 01:56:42 PDT 2015


On Monday, 14 September 2015 at 07:05:23 UTC, Meta wrote:
>
> You could turn it into a Tuple and use the `expand` method to 
> get a TypeTuple (AliasSeq).
>
> import std.typecons;
> import std.typetuple;
> import std.stdio;
>
> template genTypeList(T, size_t n)
> {
> 	static if (n <= 1)
> 	{
> 		alias genTypeList = T;
> 	}
> 	else
> 	{
> 		alias genTypeList = TypeTuple!(T, genTypeList!(T, n - 1));
> 	}
> }
>
> auto asTuple(T, size_t n)(ref T[n] arr)
> {
> 	return Tuple!(genTypeList!(T, n))(arr);
> }

BTW: What about .tupleof? Isn't that what should be used here?


More information about the Digitalmars-d-learn mailing list