| |
 | Posted by monkyyy in reply to Nick Treleaven | Permalink Reply |
|
monkyyy 
Posted in reply to Nick Treleaven
| On Friday, 27 June 2025 at 11:38:29 UTC, Nick Treleaven wrote:
> On Wednesday, 25 June 2025 at 17:09:26 UTC, monkyyy wrote:
> On Wednesday, 25 June 2025 at 11:44:01 UTC, Nick Treleaven wrote:
> I don't know what verbose syntax you mean. A sequence automatically expands.
nested templates are always possible but the syntax rapidly breaks down into something quite hard to read and unclear for users how to call
OK. There is another option if we're considering API changes:
template Pack(T...)
{
alias Expand = T;
}
template MyTemplate(alias pack, int line=__LINE__) { ... }
Then use MyTemplate!(Pack!(my, args)) . Inside MyTemplate the pack parameter has to use the Expand member to access the sequence.
> alias seq(T...)=T;
template pair(alias T,alias S){alias _1=T; alias _2=S;}
template foo(T...){
template foo(S...){
alias foo=seq!();
static foreach(I;0..T.length<S.length?T.length:S.length){
foo=seq!(foo,pair!(T[I],S[I]));
}}}
unittest{
alias _=foo!(int,bool,float);
alias bar=_!(1,2);
import std;
bar.stringof.writeln;
}
If you tried to do the same with special tokens, how the user sets up the call site would effect __LINE__ is it offset by 1? did they manage to inline it entirely?
Incidentally, I've never understood why (foo!(int,bool,float))!(1,2) isn't supported. Then we could remove:
https://dlang.org/phobos/std_meta.html#Instantiate
the builder pattern works rn, I think Id want foo!(...)!(...) to work to be better api, lisp ()'s that way lies
alias seq(T...)=T;
template pair(alias T,alias S){alias _1=T; alias _2=S;}
template foo(T...){
template sndlist(S...){
alias foo=seq!();
static foreach(I;0..T.length<S.length?T.length:S.length){
foo=seq!(foo,pair!(T[I],S[I]));
}}}
unittest{
alias bar=foo!(int,bool,float).sndlist!(1,2);
import std;
bar.stringof.writeln;
}
|