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