July 11, 2012
Giving Array an opApply operator fixes both problems:

1) It allows modifying the elements when accessed with "ref".
2) It allows writing "++a" even though "++front" isn't supported.

I implemented this and made a pull request:
https://github.com/D-Programming-Language/phobos/pull/683

I implemented both opApply and opApplyReverse.
I implemented it both for Array.Range and Array (see: http://forum.dlang.org/thread/rxpbtrawpjzvdfuuwmwp@forum.dlang.org)
I implemented correct behavior for "break" cases.
I documented the public opApply.
I wrote a complete unit test.
I tested && unittested it.

This is my first time doing this, so please forgive me if I did something wrong :(

----
If this gets validated, then maybe the same should be done to the other containers? AFAIK, none of them work correctly with foreach(ref).

----
Note that i did not touch Array!bool. This is because in that case, I cannot, even internally, pass a bool by reference to the delegate.

A workaround would be to read a bool into a temporary, pass temporary to the delegate, write back to container. However, I do not know how to distinguish the case where the delegate modifies the bool or not, making the general case too expensive.

I preferred not touching it, and doing things one at a time.
----

Thank you all for the time you have already invested in this thread (as well as the others...)
July 16, 2012
andralex wrote:
> We need to improve ranges instead of using opApply for such trivial
> iteration patterns. Apologies that the thread didn't make this clear.
> Will close this now - sorry.

Thanks for taking the time to process my pull request. I'd argue that we could keep the "opApply fix" until ranges are improved, but at the same time, keeping things (arguably) "broken" may motivate for improvement more :)

That said, given the whole "return by value" thing for closed containers, and the fact that "front" can't be forwarded a operators, I'm curious to known just _HOW_ ranges *could* ever be improved to support the current scenario.

I'll drop the issue here regardless, but I will admit that I don't see how any solution other than opApply could ever work...
July 16, 2012
On Tuesday, 10 July 2012 at 22:22:12 UTC, Timon Gehr wrote:
> 'scope ref' ?

http://d.puremagic.com/issues/show_bug.cgi?id=8121
1 2 3
Next ›   Last »