digitalmars.D.bugs - [Issue 16642] New: byCodeUnit doesn't work AutodecodableStrings
- via Digitalmars-d-bugs (60/60) Oct 27 2016 https://issues.dlang.org/show_bug.cgi?id=16642
https://issues.dlang.org/show_bug.cgi?id=16642 Issue ID: 16642 Summary: byCodeUnit doesn't work AutodecodableStrings unless they're actually strings or alias a variable that's a string Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: issues.dlang jmdavisProg.com This code fails to compile import std.utf; struct S { string s; string str() { return s; } alias str this; } void main() { auto s = S("hello"); auto range = byCodeUnit(s); } Similarly, this fails to compile import std.utf; enum E { a = "hello" } void main() { auto s = E.a; auto range = byCodeUnit(s); } Also, this compiles but uses the alias rather than the range API and thus fails the assertion: import std.range.primitives; import std.utf; static struct RangeAndStringish { string data; string s; alias s this; bool empty() { return data.empty; } char front() { return data[0]; } void popFront() { data = data[1 .. $]; } } void main() { auto fn = RangeAndStringish("test.d", "other"); auto x = fn.byCodeUnit(); assert(x.front == 't'); } I suppose that it could be argued that this last case is doing the right thing - or at least that it's ambiguous, but normally, an implicit conversion is only supposed to be used if the type itself doesn't work directly, and in this case, the type itself would work without the implicit conversion. --
Oct 27 2016