File IO: C# streams VS iterators?

Lionello Lunesu lionello at lunesu.remove.com
Thu Nov 7 19:22:28 PST 2013


On 11/8/13, 8:57, DDD wrote:
> I was watching a dconf talk about porting C# code to D. One thing that
> came up was there isn't anything like C# streams for D. Walter said he
> thinks iterators (unless I remember wrong) is superior. The speaker
> agreed but said it isn't a drop in replacement so that is an issue if
> you want to port.
>
> I haven't access file in D and i'm completely confused. What are
> iterators in regards to file IO?

There are several ranges that can be used for file IO, for example 
http://dlang.org/phobos/std_stdio.html#.File.byChunk and 
http://dlang.org/phobos/std_stdio.html#.File.byLine . C# Stream has no 
such capability, which is why you have TextReader and TextWriter on top 
of streams, etc..

However, sometimes it's useful to have polymorphism for accessing 
streams, especially when porting C#/java code to D. In that case it 
would be pretty trivial to port the base classes to D and implement them 
using the D ranges.

L.



More information about the Digitalmars-d-learn mailing list