String interpolation, after a healthy debate on discord

Daniel N no at public.email
Tue Dec 14 20:07:43 UTC 2021


On Tuesday, 14 December 2021 at 16:15:28 UTC, WebFreak001 wrote:
> ```d
> string name = readln();
> auto greeting = text!(__header!..., "hello ", name, "!");
> ```
>
> that wouldn't work because name is a runtime variable and you 
> are trying to use it as a template parameter here.
>

I assumed it works with alias/variadic params...?

```d
import std;

int sum(Vs...)()
{
     int sum = 0;

     foreach(v ; Vs)
         sum += v;

     return sum;
}

void main()
{
     int a = to!int(readln());
     sum!a.writeln;
}
```



More information about the Digitalmars-d mailing list