Challenge: write a template-instance free dispatcher for text printing
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Mon May 25 15:51:49 UTC 2026
On 26/05/2026 3:35 AM, Adam D. Ruppe wrote:
> On Monday, 25 May 2026 at 15:19:51 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> So let's see if D can do it, but... There are two rules.
>
> Use D1's writeln, it was a runtime variadic instead of a template.
Must be at CT, no runtime shenanigans.
>> dispatcher("prefix", i" $(someVar)/$(someVar) = $(text) ", "suffix");
>
> something like this is what my arsd.core thing does:
> https://github.com/adamdruppe/arsd/blob/master/core.d#L11053
>
> it reduces most input to small, factored helper functions to minimize
> generated code. also supports formatting via a wrapper:
>
> assert(toStringInternal(5.4364.formatArgs(precision: 2)) == "5.44");
That works if you can lower it to a foreach, however the key requirement
is being able to see both the header, footer, and everything in between.
Once you can see it, then you need to be able to manipulate it using CT
constructs.
More information about the Digitalmars-d
mailing list