digitalmars.D.learn - What's the current phobos way to define generic data sources and
- Hannes Steffenhagen (4/4) Apr 16 2014 I've looked at std.stream, but it says in big red scary letters
- David Nadlinger (5/9) Apr 16 2014 Have you looked into input and output ranges? Without knowing the
- Hannes Steffenhagen (4/4) Apr 17 2014 I wanna write a parser that can read the input text from an
- John Colvin (5/10) Apr 17 2014 I would recommend writing a range using a struct instead of
- Hannes Steffenhagen (8/8) Apr 17 2014 I've never said anything about inheriting from InputRange, just
- H. S. Teoh via Digitalmars-d-learn (13/23) Apr 17 2014 Please note that InputRange, as defined in std.range, is a *wrapper*
I've looked at std.stream, but it says in big red scary letters that I probably shouldn't be using it. Is there a suitable replacement? If not, I'd just roll my own and provide a couple of templates to automatically generate wrappers for them.
Apr 16 2014
On Wednesday, 16 April 2014 at 21:05:30 UTC, Hannes Steffenhagen wrote:I've looked at std.stream, but it says in big red scary letters that I probably shouldn't be using it. Is there a suitable replacement? If not, I'd just roll my own and provide a couple of templates to automatically generate wrappers for them.Have you looked into input and output ranges? Without knowing the specific details of what you need, ranges would be the way to go. David
Apr 16 2014
I wanna write a parser that can read the input text from an arbitrary source. That's going to be files for most of the time, but I don't want to unnecessarily limit it. It's a line based format, so I supposed InputRange!string would do in this case?
Apr 17 2014
On Thursday, 17 April 2014 at 08:45:29 UTC, Hannes Steffenhagen wrote:I wanna write a parser that can read the input text from an arbitrary source. That's going to be files for most of the time, but I don't want to unnecessarily limit it. It's a line based format, so I supposed InputRange!string would do in this case?I would recommend writing a range using a struct instead of inheriting from InputRange. See here for an introduction to ranges: http://ddili.org/ders/d.en/ranges.html
Apr 17 2014
I've never said anything about inheriting from InputRange, just that I'd take an InputRange as a parameter. Anyway I changed my signature to Result parse(T)(T lines) if(isInputRange!T && is(ElementType!T == string)); Still not sure if that's the best way to do it, but it definitely is the one that proved to be the least hassle to use for my simple test cases.
Apr 17 2014
On Fri, Apr 18, 2014 at 01:30:00AM +0000, Hannes Steffenhagen via Digitalmars-d-learn wrote:I've never said anything about inheriting from InputRange, just that I'd take an InputRange as a parameter. Anyway I changed my signature to Result parse(T)(T lines) if(isInputRange!T && is(ElementType!T == string)); Still not sure if that's the best way to do it, but it definitely is the one that proved to be the least hassle to use for my simple test cases.Please note that InputRange, as defined in std.range, is a *wrapper* class, intended for use in handling runtime polymorphism of ranges. It is not to be confused with the *concept* of an input range, which can be any type that provides the range API. The general practice in D is to use a template parameter for functions that take range parameters, so that the function can be instantiated for any type that satisfies the range API (including InputRange). InputRange generally is used by the code that *creates* the range, when it needs to be able to switch between different range types at runtime. T -- This sentence is false.
Apr 17 2014