Range returning an array
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Apr 9 16:31:59 PDT 2013
On Tue, Apr 09, 2013 at 07:18:25PM -0400, Steven Schveighoffer wrote:
> On Tue, 09 Apr 2013 18:53:56 -0400, Joseph Rushton Wakeling
> <joseph.wakeling at webdrake.net> wrote:
>
> >On 04/10/2013 12:50 AM, Joseph Rushton Wakeling wrote:
> >>I did consider something like that.
> >
> >By the way: the reason that I rejected the temporary-variable choice
> >was that I couldn't really see the difference cost-wise between doing
> >that, versus returning var.dup from front(). Especially as it's not
> >necessarily guaranteed that front will be called frequently (I might
> >just popFront() until the range is empty and then take the final
> >front value).
>
> Calling front after empty is not good range policy, once empty,
> front is possibly invalid or points at invalid memory.
[...]
I believe it was proposed that .front should assert if .empty returns
true. Personally I think that's a bit too extreme, but nevertheleses, I
agree that calling .front after .empty returns true is sloppy coding,
and can easily lead to bugs or runtime errors.
T
--
The two rules of success: 1. Don't tell everything you know. -- YHL
More information about the Digitalmars-d-learn
mailing list