Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2
Dukc
ajieskola at gmail.com
Wed Feb 3 15:54:53 UTC 2021
On Friday, 29 January 2021 at 19:10:55 UTC, Steven Schveighoffer
wrote:
> On 1/29/21 7:58 AM, Dukc wrote:
>> I was mainly thinking that I'd have easier time
>> differentiating between an `int` in interpolated string and
>> `int` passed before/after the interpolated string.
>
> We debated whether one should be able to figure out the
> original interpolation string from the parameters. I don't
> think it's necessary, and adds unnecessary complexity.
>
> Just passing the expression data directly makes things easy to
> deal with instead of adding an extra type to deal with.
>
> If you can come up with a reasonable use case for
> differentiating, we can discuss.
Okay, finally did this:
```
void writeAtPositions(T...)(char[] wArea, T args)
{ import std;
char[] outp = wArea;
foreach(arg; args)
static if(is(typeof(arg) : size_t) && !is(typeof(arg) : char))
{ outp = wArea[arg .. $];
} else
{ auto argStr= arg.text;
outp[0 .. argStr.length] = argStr[];
outp = outp.drop(argStr.length);
}
}
void main()
{ import std.stdio;
char[] text = "x=000,y=000,z=000".dup;
text.writeAtPositions(2, '2', "55", 16, "6");
text.writeln;
}
```
Consider passing ints in interpolated strings to
`writeAtPositions`. Only change needed to work with my suggestion
would be adding `!__traits(isSame, TemplateOf(typeof(arg),
interp))` to the `static if`, (I assume interp!int would have
`alias value this`). If the interpolated string `int`s are passed
like any `int`s, one would probably have to manually cast the
`int`s among interpolated strings to strings, to work with this
function.
More information about the Digitalmars-d
mailing list