how to do this meta-programming? print the address of random element's address of a variable length of arrays?

H. S. Teoh hsteoh at
Sun Sep 13 04:30:33 UTC 2020

On Sat, Sep 12, 2020 at 07:31:57PM +0000, mw via Digitalmars-d-learn wrote:
> I've tried something like this: the AliasSeq specify the logical
> divide
>    printRandomElemAddr(AliasSeq!(extraA, extraB, extraC, extraD), a, b, c);
> but cannot make it work.

Yes, because AliasSeq auto-expands, so `func(AliasSeq!(A,B,C),
AliasSeq!(D,E,F))` is equivalent to `func(A,B,C,D,E,F)`.

> (I'm asking for a more general solution, e.g. what if we have 3, or N
> sets of variadic parameters?)
> Looks like we can only pass 1 variadic parameters, then the question
> is what's the best way to divide it?
> Is there any special marker (variable or type?) can be used to divide?
> and what's the staticSplit?

Maybe the nested templates hack could be used? It depends on what
exactly you're trying to do though:

	template myFunc(Args1...) {
		template myFunc(Args2...) {
			auto myFunc(/* runtime params here */) {
				// you can use Args1.length and
				// Args2.length here.

	myFunc!(A,B,C)!(D,E,F)(/* runtime args here */);

Alternatively, define a non-eponymous version of AliasSeq that will
allow you to pass multiple lists of compile-time parameters without
auto-expanding and coalescing them:

	template WrappedSeq(T...) {
		// N.B.: not eponymous
		alias members = T;

	auto myFunc(Args1, Args2)(/*runtime params*/) {
		alias list1 = Args1.members; // need manual unwrap
		alias list2 = Args2.members;

	// (Yeah the caller side will look ugly. C'est la vie.)
	myFunc!(WrappedSeq!(A,B,C), WrappedSeq!(D,E,F))(/*runtime args*/);


Why can't you just be a nonconformist like everyone else? -- YHL

More information about the Digitalmars-d-learn mailing list