[Issue 2081] New: Foreach over Stream appears broken

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 8 14:58:27 PDT 2008


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 at digitalmars.com
        ReportedBy: jlquinn at 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)


-- 



More information about the Digitalmars-d-bugs mailing list