You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Autodecode strikes again! Consider the following:
import std.range;
void main() {
auto s = "test".take(3);
string str = s[];
}
This fails with s does not have operator []. Make it int and it works:
import std.range;
void main() {
auto s = [1,2,3,4].take(3);
int[] str = s[];
}
I propose that it should work for strings too. First, autodecode should be killed wholly and permanently. But if that isn't going to happen, we can still capture it all regardless:
If the original range hasLength and hasSlicing and is already of the char type, when we ask for the whole thing, it is still a constant time function: there's no need to decode characters in the middle because we know we want it all. It is unambiguous if you want the nth code unit or the nth code point, since the whole thing are the same in both cases anyway.
So I say we add a no-arg opSlice that just returns the whole view of the underlying string, thus enabling zero-cost conversion back to string.
foreach(chunk; "foo".chunks(3))
string s = chunk[];
would work, whereas now it doesn't and I don't think there even is a free way to get it back to string type - suggestions like to!string are wasting computer time.
The text was updated successfully, but these errors were encountered:
destructionator (@adamdruppe) reported this on 2018-12-12T13:26:03Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=19480
Description
Autodecode strikes again! Consider the following: import std.range; void main() { auto s = "test".take(3); string str = s[]; } This fails with s does not have operator []. Make it int and it works: import std.range; void main() { auto s = [1,2,3,4].take(3); int[] str = s[]; } I propose that it should work for strings too. First, autodecode should be killed wholly and permanently. But if that isn't going to happen, we can still capture it all regardless: If the original range hasLength and hasSlicing and is already of the char type, when we ask for the whole thing, it is still a constant time function: there's no need to decode characters in the middle because we know we want it all. It is unambiguous if you want the nth code unit or the nth code point, since the whole thing are the same in both cases anyway. So I say we add a no-arg opSlice that just returns the whole view of the underlying string, thus enabling zero-cost conversion back to string. foreach(chunk; "foo".chunks(3)) string s = chunk[]; would work, whereas now it doesn't and I don't think there even is a free way to get it back to string type - suggestions like to!string are wasting computer time.The text was updated successfully, but these errors were encountered: