Overhauling the notion of output range

Michel Fortin michel.fortin at michelf.com
Mon Jul 12 13:38:17 PDT 2010


On 2010-07-12 13:49:50 -0400, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> The point is that with a delegate you must choose between accepting E 
> and E[]. Given the constraint, it's better for everyone to accept E[] 
> and let put() take care of the occasional E by doing the wraparoo 
> (&elem)[0..1].

If this means what I think, it means put() cannot be memory safe. 
Making an array from a stack variable and passing it around cannot be 
safe unless you can trust this reference won't escape the scope of the 
delegate you're calling (and there's no way to enforce that for dynamic 
arrays). To be safe, all you can do is copy the element on the heap. Am 
I wrong?

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list