On Friday, 28 March 2014 at 23:14:56 UTC, Tobias Müller wrote:
On Thursday, 27 March 2014 at 20:49:16 UTC, Walter Bright wrote:
On 3/27/2014 12:21 PM, Rainer Schuetze wrote:
This loop is intuitive. Not being allowed to call empty or
front multiple times
or not at all is unintuitive. They should not be named as if
they are properties
then.
I can concede that. But I can't concede being able to call
front without first calling empty, or calling popFront without
calling empty and front, or requiring 'pump priming' in the
constructor.
Disclaimer: I'm a C++ programmer just lurking here, I've never
actually used D.
I find it very counter-intuitive that 'empty' is required before
front or popFront.
Since 'pump priming' in the constructor isn't wanted either, i'd
suggest the following protocol:
while (popFront())
{
front;
}
In c++ if you had a list or deque you would obviously did
if(empty()) before calling front() too, and the before a call to
pop_front(). Container is kind of range and in c++ it looks
exactly the same:
while (!cont.empty())
{
auto& var = cont.front();
cont.pop_front(); // consume
}
3 operations are needed.