On 12/30/19 6:31 PM, H. S. Teoh wrote:
On Mon, Dec 30, 2019 at 03:09:58PM -0800, H. S. Teoh via Digitalmars-d-learn
I suspect the cause is that whatever Grapheme.opSlice returns is going
out-of-scope when used with .map, that's why it's malfunctioning.
Haha, it's actually right there in the Grapheme docs for the opSlice
Random-access range over Grapheme's $(CHARACTERS).
Warning: Invalidates when this Grapheme leaves the scope,
attempts to use it then would lead to memory corruption.
Looks like when you use .map over the Grapheme, it gets copied into a
temporary, which gets invalidated when map.front returns. Somewhere
we're missing a 'scope' qualifier...
Then the original example should be fixable by putting "ref" in for all
But this is kind of disturbing. Why does the grapheme do this? The
original data is not scoped.
writeln(" Text = ", gr1.map!((ref g) => g).joiner.to!string);