q about slices, strings
ag0aep6g
anonymous at example.com
Sat Jul 13 21:28:59 UTC 2019
On 13.07.19 22:35, Kevin Bailey wrote:
> int[char[2]] aa;
> auto arr = "ABBBA";
>
> foreach (i; 0 .. arr.length - 1)
> aa[arr[i .. $][0 .. 2]]++;
>
> which I changed to:
>
> aa[arr[i .. i+2][0 .. 2]]++;
>
> in the hopes of only doing:
>
> aa[arr[i .. i+2]]++;
>
> The question is: Why is the [0..2] still necessary?
>
[...]
>
> So why isn't arr[i .. i+2] convertible? Is dmd behind the spec here?
Looks like it. It works in the most basic context:
char[2] sa = arr[i .. i + 2];
And it works in the AA context when you use the most basic kind of
expression:
aa[arr[0 .. 2]]++;
So as far as I can tell, it's just a bug that more complex expressions
fail in more complex contexts. It should work the same.
More information about the Digitalmars-d-learn
mailing list