Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-27 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 27 April 2020 at 05:06:21 UTC, anon wrote: To implement your option A you could simply use std.range.enumerate. Would something like this work? import std.algorithm.iteration : map; import std.algorithm.searching : until; import std.range : tee; size_t bytesConsumed; auto result =

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 27 April 2020 at 04:51:54 UTC, Steven Schveighoffer wrote: On 4/26/20 11:38 PM, Jon Degenhardt wrote: Is there a better way to write this? I had exactly the same problems. I created this to solve the problem, I've barely tested it, but I plan to use it with all my parsing

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 27 April 2020 at 04:41:58 UTC, drug wrote: 27.04.2020 06:38, Jon Degenhardt пишет: Is there a better way to write this? --Jon I don't know a better way, I think you enlist all possible ways - get a value using either `front` or special range member. I prefer the second variant,

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread anon via Digitalmars-d-learn
To implement your option A you could simply use std.range.enumerate. Would something like this work? import std.algorithm.iteration : map; import std.algorithm.searching : until; import std.range : tee; size_t bytesConsumed; auto result = input.map!(a => a.yourTransformation )

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/26/20 11:38 PM, Jon Degenhardt wrote: I have a string that contains a sequence of elements, then a terminator character, followed by a different sequence of elements (of a different type). I want to create an input range that traverses the initial sequence. This is easy enough. But

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread drug via Digitalmars-d-learn
27.04.2020 06:38, Jon Degenhardt пишет: Is there a better way to write this? --Jon I don't know a better way, I think you enlist all possible ways - get a value using either `front` or special range member. I prefer the second variant, I don't think it is less consistent with range

Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread Jon Degenhardt via Digitalmars-d-learn
I have a string that contains a sequence of elements, then a terminator character, followed by a different sequence of elements (of a different type). I want to create an input range that traverses the initial sequence. This is easy enough. But after the initial sequence has been traversed,