Reducing variadic template combinatorics (C++ was onto something)

Paul Backus snarwin at gmail.com
Tue Oct 14 15:29:04 UTC 2025


On Tuesday, 14 October 2025 at 04:30:49 UTC, Steven Schveighoffer 
wrote:
> But... I still want to write `writelines(1, 2, 3, 4)`. The 
> ergonomics there are nice! Is there some way we can capture 
> this same reduction in complexity while still keeping the nice 
> syntax?

The answer to this, of course, is Lisp-style AST macros. You 
write some code that describes the AST transformation from 
`writelines(1, 2, 3, 4);` to `writeln(1); writeln(2); writeln(3); 
writeln(4);`, and the compiler executes this code at compile time 
and replaces the original AST with the result. Because the macro 
is totally ephemeral, it does not need to have space allocated 
for each expansion in the template cache, nor a unique name 
generated for the symbol table, nor time spent inlining the 
wrapper functions during optimization (or failing to), nor time 
spent during codegen and linking to process those wrapper 
functions.

Since D will never have AST macros, we are condemned for eternity 
to suffer from either template bloat or awkward syntax.


More information about the Digitalmars-d mailing list