printf() metaprogramming challenge

Yuxuan Shui yshuiv7 at gmail.com
Thu May 23 22:58:24 UTC 2019


On Thursday, 23 May 2019 at 19:33:15 UTC, Walter Bright wrote:
> [snip]
>
> I completely failed at that. I suspect the language has a 
> deficiency in manipulating expression tuples.
>
> 

What a coincidence, I had this exact problem today as well. It 
seems currently the only way to do this is either with mixins, or 
using tuple.

Assuming you already have all of the arguments in a tuple:

     auto args = tuple(...);

And args[x] is a string, you can do this:

     auto args_prime = tuple(args[0..x], args[x].length, 
args[x].ptr, args[x..$]);

You then need to do some template magic to expand all such 
arguments... Using mixin is probably better.




More information about the Digitalmars-d mailing list