Skip to content

std.algorithm.remove: Fix constraints and change popBack loop to popBackN#2256

Merged
DmitryOlshansky merged 2 commits intodlang:masterfrom
Safety0ff:popbackn
Jul 4, 2014
Merged

std.algorithm.remove: Fix constraints and change popBack loop to popBackN#2256
DmitryOlshansky merged 2 commits intodlang:masterfrom
Safety0ff:popbackn

Conversation

@Safety0ff
Copy link
Contributor

See also: https://issues.dlang.org/show_bug.cgi?id=8930
Remove with swap strategy stable requires bidirectional range for popback.

@DmitryOlshansky
Copy link
Member

So it doesn't solve issue 8930 but patches the constraints. Anyhow a net progress, so LGTM.

std/algorithm.d Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/popBackN/popBackExactly/

popBackN will actually pop "up to" N elements, checking for empty in between each call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change all of the pop____Ns to pop____Exactlys? Note that the parameter is derived from input, so erroneous input will cause undefined behaviour.
EDIT: I suppose we can use the other popBack's to validate calling popBackExactly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, change pop____N to pop____Exactly.

Yes, it will cause undefined behavior, but the input is erroneous anyways.

@monarchdodra
Copy link
Collaborator

Well, arguably, you don't need lvalue elements to be able to swap. For example swapFront will do a value swap if there is not lvalue access. I had started working on a fix, but got sidetracked with other issues.

I perfectly fine with constraining the function to only accept what it actually works on, and we can relax them later once we have a better working implementation.

@Safety0ff
Copy link
Contributor Author

I perfectly fine with constraining the function to only accept what it actually works on, and we can relax them later once we have a better working implementation.

This was my line of thinking, btw I'm not interested fixing 8930.

@Safety0ff
Copy link
Contributor Author

@monarchdodra ping, could you please answer my questions?

@Safety0ff
Copy link
Contributor Author

@DmitryOlshansky Could we please just move forward with this? If somebody wants to optimize with pop___Exactly later on, they can do so.

@monarchdodra
Copy link
Collaborator

@DmitryOlshansky Could we please just move forward with this? If somebody wants to optimize with pop___Exactly later on, they can do so.

Sorry I didn't see this any earlier. Just do it now, and we're good to go.

@Safety0ff
Copy link
Contributor Author

Ok rebased on top of master and added a commit for the change from pop___N to pop____Exactly.

Note that I changed the pop____N's in the unstable version as well. The first commit only touched the constraints for the unstable version.

@DmitryOlshansky
Copy link
Member

Auto-merge toggled on

@Safety0ff
Copy link
Contributor Author

Thanks!

@monarchdodra
Copy link
Collaborator

Hey, sorry I wasn't that proactive reviewing this pull. Things have been difficult for me recently IRL. Thanks for sticking with this.

DmitryOlshansky added a commit that referenced this pull request Jul 4, 2014
std.algorithm.remove: Fix constraints and change popBack loop to popBackN
@DmitryOlshansky DmitryOlshansky merged commit cc92017 into dlang:master Jul 4, 2014
@Safety0ff Safety0ff deleted the popbackn branch July 4, 2014 19:09
@Safety0ff
Copy link
Contributor Author

Hey, sorry I wasn't that proactive reviewing this pull. Things have been difficult for me recently IRL. Thanks for sticking with this.

Don't worry about it. :)
Know you and a few other people carry a large amount of weight for this project and I appreciate what you do.
I also understand that oftentimes PR's get abandoned by those who initiate them.
My impatience stemmed more from the fact that we have a considerable amount of people willing to spend hours going around in circles in the forums rather than help things move forward concretely on github.

9rnsr pushed a commit to 9rnsr/phobos that referenced this pull request Jul 7, 2014
std.algorithm.remove: Fix constraints and change popBack loop to popBackN
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.

3 participants