no [] operator overload for type Chunks!(char[])

Ali Çehreli acehreli at yahoo.com
Wed May 30 21:27:44 UTC 2018


On 05/30/2018 02:19 PM, Malte wrote:
> Why does this code complain at the last line about a missing [] operator 
> overload?
> 
> auto buffer = new char[6];
> auto chunked = buffer.chunks(3);
> chunked[1][2] = '!';
> 
> Same happens with wchar.
> Dchar and byte work as expected.

UTF-8 auto decoding strikes again. :)

Even though the original container is char[], passing it through Phobos 
algorithms generated range of dchar. The thing is, those dchar elements 
are generated (decoded from chars) "on the fly" as one iterates over the 
range. Which means, there is no array of dchar to speak of, so there is 
no random access.

Ali


More information about the Digitalmars-d-learn mailing list