how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();
Ali Çehreli
acehreli at yahoo.com
Mon Jun 22 20:58:58 UTC 2020
On 6/22/20 1:46 PM, mw wrote:
> so `front` is peek, and `popFront` is the pop action whose return type
> is `void`, why we need two *separate* calls instead of just let
> `popFront` return T
Others have other explanations for this but my understanding is about
exception safety: If it changed internal state and returned the front
object, you would no be able to make a function like popFront() strongly
exception safe. (There are ample documentation for this topic in C++
circles.)
Another reason is cohesion: We want functions to have as little
responsibility as possible (ideally single).
> (or do we have another function for this)?
There are many useful functions in std.range:
https://dlang.org/phobos/std_range.html
The "take" and "drop" functions may be useful.
Ali
More information about the Digitalmars-d-learn
mailing list