Skip to content

Conversation

monarchdodra
Copy link
Collaborator

Makes it an error to pass unequal-length ranges with requireSameLength. Allows using Zip in nothrow code.

enforce(ranges[0].empty ==
ranges[i + 1].empty,
"Inequal-length ranges passed to Zip");
assert(b == ranges[i + 1].empty, "Inequal-length ranges passed to Zip");
Copy link
Member

Choose a reason for hiding this comment

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

this effectively changes "require" to "assume" - not sure if good

@andralex
Copy link
Member

So are the changes enforce -> assert motivated by efficiency?

@monarchdodra
Copy link
Collaborator Author

this effectively changes "require" to "assume"

Technically "Require" implies no promises or assumption. "assume" and "enforce" do. "Require" is in a gray area (I think).

So are the changes enforce -> assert motivated by efficiency?

Both efficiency, and usability. The "problem" is that because the ending condition is a run-time one, these enforces over asserts are ruining it for everyone. Functions that otherwise would never throw anyways, are gratuitously marked as throwing.

This has a performance impact, and prevents them from being used in code that would otherwise be nothrow.

not sure if good

It's your call. For what it's worth, after this, I'll be working on making the stopping condition a compile time parameter (I can do this without breakage), so the issue should also spontaneously resolve, thanks to finer grained (and compile time) end conditions.

Doing this here now means users will benefit from in ASAP: the "new" Zip I'm working on will be opt-in until the old one is fully deprecated and removed. Only then can the new compile time Zip replace the old run-time one by default. So it could be a while.


Regardless, I think front/popFront can be made nothrow regardless: That's standard out of bounds checking, not input validation.

@monarchdodra
Copy link
Collaborator Author

EDIT: Of course, there's the fact that the checks are not removed in release, making the Zip much slower than it should be, even for requireSameLength.

Fix Issue 11913 - nothrow std.algorithm.zip
@JakobOvrum
Copy link
Contributor

This is a breaking change. I'd rather we just fix it in the template-parameter version.

@monarchdodra
Copy link
Collaborator Author

This is a breaking change. I'd rather we just fix it in the template-parameter version.

Yeah, probably the best idea. I'll just close this.

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