Range returning an array

Jesse Phillips Jessekphillips+D at gmail.com
Wed Apr 10 11:22:53 PDT 2013


On Tuesday, 9 April 2013 at 23:18:26 UTC, Steven Schveighoffer 
wrote:
> On Tue, 09 Apr 2013 18:53:56 -0400, Joseph Rushton Wakeling 
> <joseph.wakeling at webdrake.net> wrote:
>> 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.
>
> -Steve

I'm pretty sure he realizes this, his original code shows how he 
is doing this. He expects 'output' to hold the final front value, 
but instead it holds the empty "value."

Joseph, I think you will have to profile to decide which is the 
fastest for your use case.


More information about the Digitalmars-d-learn mailing list