www.digitalmars.com         C & C++   DMDScript  

digitalmars.dip.ideas - Varargs concatenation

reply monkyyy <crazymonkyyy gmail.com> writes:
```d
alias seq(T...)=T;
alias a=seq!int;
alias b=seq!float;
alias c=a~b;//seq!(int,float)
```

```d
alias a=seq!();
a~=int;
a~=float;//seq!(int,float)
```

Concatenation of vartatic templates will automagically grab their 
headers and combine them together

If the templates are different then the first one will be used

```d
alias a=seq!int;
alias b=AliasSeq!float;
static assert(is(a~b==seq!(int,float));
static assert(is(b~a==AliasSeq!(float,int));
```

this will allow pulling out template arguments from a reference

```d
alias badseq(T...)=void;

alias a=badseq!(int,float);
alias b=seq!()~a;//seq!(int,float)
```

it should work with templated structs/functions

```d
struct sumtype(T...){...}
alias a=seq!()~sumtype!(int,float);//seq!(int,float)
```
Jun 20
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 21/06/2025 7:55 AM, monkyyy wrote:
 alias seq(T...)=T; alias a=seq!int; alias b=seq!float; alias c=a~b;// 
 seq!(int,float)
Note: we can do this today. ```d import std.meta; template Foo() { alias A = AliasSeq!int; A = AliasSeq!(A, float); pragma(msg, A); // (int, float) } alias Foos = Foo!(); ``` Unfortunately alias assign doesn't work outside of the template. Hence the template.
 alias badseq(T...)=void; alias a=badseq!(int,float); alias b=seq!()~a;//
 seq!(int,float)
That can't work, the alias goes bye bye, and it will only see the void.
Jun 20
parent monkyyy <crazymonkyyy gmail.com> writes:
On Friday, 20 June 2025 at 20:03:29 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 
 alias badseq(T...)=void; alias a=badseq!(int,float); alias
b=seq!()~a;//
 seq!(int,float)
That can't work, the alias goes bye bye, and it will only see the void.
I think the spec says it *may* but Im pretty sure it *cant* in practice, the inherent memoization exists somewhere ```d template badseq(T...){ pragma(msg,T.stringof); alias badseq=void; } unittest{alias a=badseq!(int,float);}//prints unittest{alias a=badseq!(int,float);}//doesnt unittest{alias a=badseq!(int,float);} unittest{alias a=badseq!(int,float);} ```
Jun 20