Pitfalls of delegates inside ranges

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Mon Sep 2 06:49:08 PDT 2013


On 02/09/13 15:39, Artur Skawina wrote:
> While this may not seem ideal, sometimes you do *not* want to do it
> (when you need to keep the original context), so there are no obvious
> alternatives that would handle all cases automagically.

I'm sure there are valid use cases where this behaviour is desirable.  In fact, 
all approaches to creating reference-type structs rest on this, although in 
those cases the reference is usually a pointer to a payload rather than a 
delegate to a function.

The point is, it's a risk if you don't appreciate how value and reference types 
intermingle -- and even when you do in principle, it's easy to accidentally 
overlook in practice.  The Phobos unittests, which for RandomSample are very 
extensive, didn't catch this problem.


More information about the Digitalmars-d-learn mailing list