Range returning an array
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Thu Apr 11 03:23:53 PDT 2013
On 04/10/2013 01:18 AM, Steven Schveighoffer wrote:
> Calling front after empty is not good range policy, once empty, front is
> possibly invalid or points at invalid memory.
It's not necessarily required to actually call front with the range empty: one
could do something like,
for(; !sim.empty; sim.popFront())
v = sim.front;
... and the way that popFront() operates means that, while the output of front()
may be transient in general, the last value will remain.
Though I agree that, even in this case, it's is a potentially problematic
situation (there's something weird about the idea of a range that is transient
except for the last entry). I will have to profile with .dup enabled and see
what changes.
More information about the Digitalmars-d-learn
mailing list