Skip to content

better support of foreach for array #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

better support of foreach for array #683

wants to merge 3 commits into from

Conversation

monarchdodra
Copy link
Collaborator

See discussion "foreach ref very broken: fails to call front(val)" here:
http://forum.dlang.org/thread/uoptrrkgfczyozxtkkvi@forum.dlang.org

This fix allows writting things like:
Array!int arr;
foreach(ref a; arr)
++a;

In the sense that:

  1. arr actually gets modified as intended by ref.
  2. "++a" compiles correctly, even though "++front" doesn't allow it.

I think the pull request is complete:
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 :(

Correcting indentation (4 spaces instead of two.
Adding a few words and a period to the doc.
…ement, as empty Array s can be legitimately not isInitialized.


Ranges don't need the check, as they iterate on indexes.
@andralex
Copy link
Member

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.

@andralex andralex closed this Jul 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants