Discussion Thread: DIP 1036--String Interpolation Tuple Literals--Community Review Round 2
Imperatorn
johan_forsberg_86 at hotmail.com
Wed Feb 3 17:34:42 UTC 2021
On Wednesday, 3 February 2021 at 16:52:23 UTC, Q. Schroll wrote:
> On Friday, 29 January 2021 at 12:58:32 UTC, Dukc wrote:
>> [...]
>
> Sorry, I'm late to the game here. This reminds me of slices vs
> static arrays.
> As a reminder, to a newcomer,
> auto xs = [ 1, 2, 3 ];
> looks like it would infer int[3] as the type of xs. It is
> obviously the most descriptive type for the literal. Why would
> it infer int[] forgetting its compile-time known length and
> even do an allocation? That seems so much worse. Even
> typeof([1,2,3]) is int[] and not int[3]. We know why D does it
> the way it does and goes int[3] with no allocation only if
> requested explicitly. You can do that with a template with a
> flexible length like this:
> void takesStaticArray(size_t n)(int[n] staticArray);
> Here, `n` can usually be inferred from the argument.
>
> [...]
I also think that's reasonable, but Adam didn't seem to agree
iirc (default to string)
More information about the Digitalmars-d
mailing list