Thread overview
Mutiple AliasSeq as input to template
May 25, 2017
jmh530
May 25, 2017
jmh530
Jun 07, 2017
David Sanders
Jun 08, 2017
jmh530
May 25, 2017
I'm trying to process one AliasSeq based on the types in another. I've tried to sketch it out below. However, it doesn't work because when you combine together two AliasSeq's in the template, then it creates one AliasSeq.

The only other thing I considered was a staticMap with isIndex, but I wasn't sure if it would work with two AliasSeqs.


enum isIndex(I) = is(I : size_t);

template Process(A, B)
{
	import std.meta : AliasSeq;
	
	static if (A.length == 1)
	{
		static if (!isIndex!B[0])
			alias Process = AliasSeq!(A[0]);
		else
			alias Process = AliasSeq!(B[0]);
	}
	else static if (A.length > 1)
	{
		static if (!isIndex!B[0])
			alias Process = AliasSeq!(A[0], Process!(A[1..$], B[1..$]));
		else
			alias Process = AliasSeq!(B[0], Process!(A[1..$], B[1..$]));
	}
}

void main()
{
	import std.meta : AliasSeq;

	alias T = AliasSeq!(int[], int[]);
	alias U = AliasSeq!(int, string);
	alias V = Process!(T, U); //result should be AliasSeq!(int, int[])
}
May 25, 2017
On Thursday, 25 May 2017 at 16:36:45 UTC, jmh530 wrote:
> [snip]

I haven't played around with it fully, but it seems like the following resolves my issue in a sort of manual way:

template Process1(A, B)
{
	static if (!isIndex!B)
		alias Process1 = A;
	else
		alias Process1 = B;
}

template Process(size_t n, A...)
	if (n > 0)
{
	import std.meta : AliasSeq;
	
	alias B = A[0..n];
	alias C = A[n..$];
	
	static if (n == 1)
	{
		alias Process = AliasSeq!(Process1!(B[0], C[0]));
	}
	else static if (n > 1)
	{
		alias Process = AliasSeq!(Process1!(B[0], C[0]),
								  Process!(n - 1, B[1..$], C[1..$]));
	}
}



June 07, 2017
On Thursday, 25 May 2017 at 17:56:12 UTC, jmh530 wrote:
> On Thursday, 25 May 2017 at 16:36:45 UTC, jmh530 wrote:
>> [snip]
>
> I haven't played around with it fully, but it seems like the following resolves my issue in a sort of manual way:
>
> template Process1(A, B)
> {
> 	static if (!isIndex!B)
> 		alias Process1 = A;
> 	else
> 		alias Process1 = B;
> }
>
> template Process(size_t n, A...)
> 	if (n > 0)
> {
> 	import std.meta : AliasSeq;
> 	
> 	alias B = A[0..n];
> 	alias C = A[n..$];
> 	
> 	static if (n == 1)
> 	{
> 		alias Process = AliasSeq!(Process1!(B[0], C[0]));
> 	}
> 	else static if (n > 1)
> 	{
> 		alias Process = AliasSeq!(Process1!(B[0], C[0]),
> 								  Process!(n - 1, B[1..$], C[1..$]));
> 	}
> }

You can use nested templates to process multiple AliasSeqs like so:

enum isIndex(I) = is(I : size_t);

template Process(A...)
{
    template With(B...)
    {
        import std.meta : AliasSeq;

        static if (A.length == 0 || B.length == 0)
            alias With = AliasSeq!();
        else
        {
            static if(!isIndex!(B[0]))
                alias Process1 = A[0];
            else
                alias Process1 = B[0];
            alias With = AliasSeq!(Process1, Process!(A[1..$]).With!(B[1..$]));
        }
    }
}

void main()
{
    import std.meta : AliasSeq;

    alias T = AliasSeq!(int[], int[]);
    alias U = AliasSeq!(int, string);
    static assert(is(Process!(T).With!(U) == AliasSeq!(int, int[])));
}
June 08, 2017
On Wednesday, 7 June 2017 at 19:03:39 UTC, David Sanders wrote:
> You can use nested templates to process multiple AliasSeqs like so:
>
> [snip]

Interesting approach also.