Thread overview
allow unaccessable default arguments
Jun 18
monkyyy
Jun 21
monkyyy
Jun 25
monkyyy
6 days ago
monkyyy
June 18

void foo(Args...)(Args args,int line=__LINE__)
template foo(T...,int line=__LINE__)
void foo(T)(T[] array...,T magic=Bar!T)

While I have work arounds, it would be better just to let this happen; special tokens and dual context magic happens in headers.

June 21

On Wednesday, 18 June 2025 at 19:11:36 UTC, monkyyy wrote:

>

void foo(Args...)(Args args,int line=__LINE__)

The above works because once instantiated, it's a non-variadic function.

>

template foo(T...,int line=__LINE__)

Could be made to work, but then, what if there's a constraint on T that forbids int value elements (e.g. if (is(T)))? People might then expect that when the last instantiation argument is an int, it matches line.

>

void foo(T)(T[] array...,T magic=Bar!T)

Again, that specific case seems OK, but what about when magic is not compatible with T? People might expect they can pass a magic argument in that case.

June 21

On Saturday, 21 June 2025 at 10:28:27 UTC, Nick Treleaven wrote:

> >

template foo(T...,int line=__LINE__)

Could be made to work, but then, what if there's a constraint on T that forbids int value elements (e.g. if (is(T)))? People might then expect that when the last instantiation argument is an int, it matches line.

Im suggesting its just made greedy, allowing special tokens to do their work; if you want to formally pass a T... before other arguments to a template you could always nest them with terrible verbose syntax.

But I think you should probably reach for that awful "builder" pattern first; special tokens on the other hand would become stylistic land mines in a builder pattern

> >

void foo(T)(T[] array...,T magic=Bar!T)

Again, that specific case seems OK, but what about when magic is not compatible with T? People might expect they can pass a magic argument in that case.

Im giving a hard case; I dont know other people using this sort of pattern of templated default arguments it can be quite tricky to get right

June 25

On Saturday, 21 June 2025 at 15:57:45 UTC, monkyyy wrote:

>

Im suggesting its just made greedy, allowing special tokens to do their work; if you want to formally pass a T... before other arguments to a template you could always nest them with terrible verbose syntax.

I don't know what verbose syntax you mean. A sequence automatically expands.

June 25

On Wednesday, 25 June 2025 at 11:44:01 UTC, Nick Treleaven wrote:

>

On Saturday, 21 June 2025 at 15:57:45 UTC, monkyyy wrote:

>

Im suggesting its just made greedy, allowing special tokens to do their work; if you want to formally pass a T... before other arguments to a template you could always nest them with terrible verbose syntax.

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

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?

June 27

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

6 days ago

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;
}