|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.bugs - [Issue 2081] New: Foreach over Stream appears broken
http://d.puremagic.com/issues/show_bug.cgi?id=2081 Summary: Foreach over Stream appears broken Product: D Version: 2.012 Platform: PC OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: Phobos AssignedTo: bugzilla digitalmars.com ReportedBy: jlquinn optonline.net I'm trying to use the foreach idiom shown in the docs for InputStream, but the compiler rejects my code. The program is: import std.cstream; import std.stream; void test() { string file = "test"; Stream f = new BufferedFile(file); foreach (ulong line, string buf; f) { derr.writefln(buf); } } The compiler complains: dmd/bin/dmd junk2.d junk2.d(8): function std.stream.Stream.opApply (int delegate(ref char[] line)) does not match parameter types (int delegate(ref ulong __applyArg0, ref invariant(char)[] __applyArg1)) junk2.d(8): Error: cannot implicitly convert expression (__foreachbody15) of type int delegate(ref ulong __applyArg0, ref invariant(char)[] __applyArg1) to int delegate(ref ulong n, ref wchar[] line) -- May 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2081 shro8822 vandals.uidaho.edu changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement ------- Comment #1 from shro8822 vandals.uidaho.edu 2008-05-08 17:09 ------- try this foreach (ref string buf; f) there isn't a opApply with an index value, But IMHO there should be (converting to feature request) -- May 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2081 jlquinn optonline.net changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|enhancement |normal ------- Comment #2 from jlquinn optonline.net 2008-05-08 17:18 ------- The code becomes: foreach (ref string buf; f) { which the compiler still dislikes: lexicon.d(92): function std.stream.Stream.opApply (int delegate(ref char[] line)) does not match parameter types (int delegate(ref invariant(char)[] buf)) lexicon.d(92): Error: cannot implicitly convert expression (__foreachbody15) of type int delegate(ref invariant(char)[] buf) to int delegate(ref ulong n, ref wchar[] line) Changing back to a bug :-) BTW, why is "ref" needed? If so, the docs aren't clear about that and need to be updated. -- May 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2081 ------- Comment #3 from shro8822 vandals.uidaho.edu 2008-05-08 17:34 ------- If it's a bug, than it's a bug in DMD. If it's related to phobos than it's a feature request because it's operating correctly, just not the way we want it to. I use D1.0 so I can't test it but try this foreach (ref char[] buf; f) { -- May 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2081 ------- Comment #4 from jlquinn optonline.net 2008-05-08 20:28 ------- (In reply to comment #3)If it's a bug, than it's a bug in DMD. If it's related to phobos than it's a feature request because it's operating correctly, just not the way we want it to. May 08 2008
|