digitalmars.D - std.stream example
- Me Here (23/23) Apr 28 2008 I just tried to compile the following example ffrom the std.stream docs:
- Simen Kjaeraas (7/32) Apr 28 2008 s:
- Gide Nwawudu (11/34) Apr 28 2008 Example is wrong.
I just tried to compile the following example ffrom the std.stream docs: import std.stdio; import std.stream; int main (char[][] args) { Stream file = new BufferedFile( "myfile" ); foreach( ulong n, string line; file ) { writefln( "line %d: %s", n,line ); } file.close(); return 0; } I'm getting: fhash.d(31): function std.stream.Stream.opApply (int delegate(ref char[] line)) does not match parameter types (int delegate(ref ulong __applyArg0, ref invariant(char)[] __applyArg1)) fhash.d(31): 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) Have I got my libraries screwed up? Or c&p the example incorrectly? Or is the example just out of date or otherwise screwed? Cheers, b. --
Apr 28 2008
On Mon, 28 Apr 2008 15:36:18 +0200, Me Here <p9e883002 sneakemail.com> = wrote:I just tried to compile the following example ffrom the std.stream doc=s:import std.stdio; import std.stream; int main (char[][] args) { Stream file =3D new BufferedFile( "myfile" ); foreach( ulong n, string line; file ) { writefln( "line %d: %s", n,line ); } file.close(); return 0; } I'm getting: fhash.d(31): function std.stream.Stream.opApply (int delegate(ref char=[] =line)) does not match parameter types (int delegate(ref ulong __applyArg0, re=f =invariant(char)[] __applyArg1)) fhash.d(31): 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) Have I got my libraries screwed up? Or c&p the example incorrectly? Or is the example just out of date or otherwise screwed? Cheers, b.Looks like a bug to me. Compiles under 1.029, not under 2.0xx. -- Simen
Apr 28 2008
On Mon, 28 Apr 2008 13:36:18 +0000 (UTC), "Me Here" <p9e883002 sneakemail.com> wrote:I just tried to compile the following example ffrom the std.stream docs: import std.stdio; import std.stream; int main (char[][] args) { Stream file = new BufferedFile( "myfile" ); foreach( ulong n, string line; file ) { writefln( "line %d: %s", n,line ); } file.close(); return 0; } I'm getting: fhash.d(31): function std.stream.Stream.opApply (int delegate(ref char[] line)) does not match parameter types (int delegate(ref ulong __applyArg0, ref invariant(char)[] __applyArg1)) fhash.d(31): 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) Have I got my libraries screwed up? Or c&p the example incorrectly? Or is the example just out of date or otherwise screwed? Cheers, b.Or is the example just out of date ...Example is wrong. D1 declares a string as char[], D2 declares it as invariant(char)[]. It does not compile because the line variable being passed to Stream.onApply should be mutable. So foreach( ulong n, string line; file ) changes to: foreach( ulong n, char[] line; file ) - or - foreach( ulong n, ref char[] line; file ) Gide
Apr 28 2008