On Friday, 10 January 2014 at 14:13:37 UTC, marcpmichel wrote:
On Friday, 10 January 2014 at 14:02:21 UTC, Manu wrote:
I won't start another annoying thread.
What's the go with popFront()... it returns nothing?
I almost always want to pop and return the front element. I
can't find a
function to do that... have I missed something again?
There isn't (at least, not that I know of). I would be trivial to
implement, but because it would be implemented in terms of
front/popFront, it would not be any faster.
*However*, depending on the range type (non-transitive), popping
might instantaneously invalidate the element you are operating on
(think "byLine", that returns a "char[]", not a "string").
It seems you have to use both the .front property to access the
element, and popFront() to advance to the next element.
I can't understand why you need two methods; maybe there's a
very good reason for that.
You *need* two methods for the very simple use case of reading
without popping.
As for returning the popped element when calling pop: It's an
extra cost. C++ introduced back and pop_back (as well as pop/top)
with those exact semantics for this reason. D also adds an issue
of data integrity.