More pathological range subtleties

Marco Leise Marco.Leise at gmx.de
Tue Feb 12 14:29:07 PST 2013


Am Tue, 12 Feb 2013 13:09:33 -0800
schrieb "H. S. Teoh" <hsteoh at quickfur.ath.cx>:

> I've always felt uneasy about the way D handles ref's in foreach loops.
> It feels like it was a good idea that was carried over from D1, but
> didn't get implemented thoroughly enough to handle the new stuff in D2.
> Forcing opApply to *always* take a delegate with ref arguments is one
> indication of the deeper problem. This makes it so that the container
> can't customize its behaviour for the ref case and for the non-ref case,
> and this conflation leads to problems down the road (like people just
> passing a ref to a temporary variable when they want foreach loops to
> not change the contained elements, which leads to bugs 'cos the person
> writing the foreach loop thought things were being updated but they
> actually aren't).

Oh man, I just wrote such code today...

-- 
Marco



More information about the Digitalmars-d mailing list