Re: decodeGrapheme & static array

2020-01-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 4 January 2020 at 19:56:54 UTC, Robert M. Münch 
wrote:
But it doesn't seem to be an L-value... which I don't 
understand. I thought buf[] returns a temporary dynamic array 
initialized with the buf content.


The problem here is indeed ref, the function there tries to 
update the slice so it point to the next element and that 
requires a named variable.


Generally speaking, if your thing is not tied directly to a named 
variable it can update, it cannot be ref.


So your buf[] there refers to a named variable, which is good 
enough... but the [] cannot possibly update because buf is 
statically sized.


Just assigning to a temporary in the middle can fix this for you:

dchar[] remainingItems = buf[];
decode(remainingItems);
// note that length of remainingItems will now be smaller than it 
started


decodeGrapheme & static array

2020-01-04 Thread Robert M. Münch via Digitalmars-d-learn

I have:

Grapheme[] gr;
dchar[1] buf;
encode(buf, cast(dchar)myData);
gr =~ decodeGrapheme(buf[]);

Which gives:

Error: template std.uni.decodeGrapheme cannot deduce function from 
argument types !()(dchar[]), candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\uni.d(7164,10):
decodeGrapheme(Input)(ref Input inp)


I some how need an InputRange for buf and though that buf[] should 
work. But it doesn't seem to be an L-value... which I don't understand. 
I thought buf[] returns a temporary dynamic array initialized with the 
buf content.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster