Joining AliasSeq/TypeTuple s

Adrian Matoga via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 30 04:33:42 PDT 2016


On Tuesday, 29 March 2016 at 10:06:43 UTC, Adrian Matoga wrote:
> (...)

Another version that doesn't misbehave if first and second are of 
different lengths:

import std.meta : AliasSeq;

template RR(A...) {
	template With(B...) {
		static if (A.length == 0 || B.length == 0)
			alias With = AliasSeq!(A, B); // or static assert(0) if you 
require equal lengths
		else
			alias With = AliasSeq!(A[0], B[0], RR!(A[1 .. $]).With!(B[1 .. 
$]));
	}
}

struct S(A...) {} // needed to reliably compare AliasSeq's for 
equality

unittest {
	alias first = AliasSeq!(int, string, bool);
	alias second = AliasSeq!("abc", "def", "ghi");
	alias third = RR!first.With!second;
	static assert(is(S!third == S!(int, "abc", string, "def", bool, 
"ghi")));
	alias fourth = RR!(first[0 .. 2]).With!second;
	static assert(is(S!fourth == S!(int, "abc", string, "def", 
"ghi")));
}




More information about the Digitalmars-d-learn mailing list