printf() metaprogramming challenge

Yuxuan Shui yshuiv7 at gmail.com
Fri May 24 00:48:42 UTC 2019


On Friday, 24 May 2019 at 00:41:31 UTC, Andrei Alexandrescu wrote:
> On 5/23/19 6:58 PM, Yuxuan Shui wrote:
>> 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.
>
> Did you try .expand with the tuple?

It's 1 character shorter to just write someTuple[0..$] :)


More information about the Digitalmars-d mailing list