Issue 11252 - In operator requested for std.range.iota#5629
Issue 11252 - In operator requested for std.range.iota#5629dlang-bot merged 2 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request, @dukc! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla references
|
std/range/package.d
Outdated
| void popFront() { assert(!empty); ++current; } | ||
|
|
||
| @property inout(Value) back() inout { assert(!empty); return cast(inout(Value))(pastLast - 1); } | ||
| @property inout(Value) back() inout{ assert(!empty); return cast(inout(Value))(pastLast - 1); } |
There was a problem hiding this comment.
please keep the space
There was a problem hiding this comment.
Too small a detail to be worth cleaning imo, but as you wish.
There was a problem hiding this comment.
It churns the git blame and if we don't pay attention to avoid unrelated changes, git blame becomes useless. Also it makes things a lot harder for people who skim over the diffs.
JackStouffer
left a comment
There was a problem hiding this comment.
I still don't see much utility in this TBH. The proposed usage in the bug report is way slower than saving to a temporary and doing two comparisons in an if statement.
|
Check what was said later in the bug report... It does not do a linear search, this is a constant-time algorithm. |
|
I'm on the fence about this one. Using an operator overload on Note that the original bug report isn't even asking for testing membership in iota with non-unit step, so implementing an operator overload for |
|
Also, if I think a standalone comparison function is still better -- no need to instantiate |
|
What comes to custom types only incrementing, I think I must add a template constraint forbidding usage with non-integral types. That constraint is already there for indexing, so nothing special there. But I agree that may be a bit inconsistent way with the other library to solve this problem. On the other hand, somebody might already have an iota that needs to be checked, and forcing to retype it's parameters is a bit suboptimal. Only bit, trough. Isn't this question somewhat like c++ iterator pairs vs ranges? In that should one use two arguments to describe bounds for an area, or one where the bounds have been premade? I'll add the constraint. If you are positive it should be a three-argument between function instead of iota, close this. On the other hand, I could also change the in operation to a regular member function. EDIT: opIndex does not have any contraints, so none needed for opBinary!"in" either. In fact, the whole template requires the type to fulfill IsIntegral or IsPointer, and at least according to docs that means only built-in types. So no worries about customs. |
|
@wilzbach This doesn't add a new symbol, why do you want Andrei's review for this? |
|
An operator is a symbol, or at least equivalent to a symbol. Or do you mean module-level symbols? |
Because this seems to be like an important precedent (and is about adding a new symbol): "should we add |
andralex
left a comment
There was a problem hiding this comment.
This is useful. In fact it would be nice if iota supported some of the methods in SortedRange, too.
Please add documentation and documentation unittests.
JackStouffer
left a comment
There was a problem hiding this comment.
Well, since Andrei has approved this concept, there are two things that need to be fixed:
- Docs
- Add test for user defined types e.g.
BigInt
|
Wow, I did not even notice that iota for user-defined types before now. I agree it should support in operator if the type was fully arithmetic, but because it does not support random access anyway it is matter of a separate pr. So no need for custom-type unittests either. I'll do the documentation, trough. |
That's not as easy as it sounds (you can read in some bugzilla issue why), so we should leave that for another PR. @dukc mind the docs and this should be good to go. |
|
I won't probably do it this nor the next week because I have other stuff to do but then, I will. |
|
One more thing: iota should support contains similar to SortedRange. The backend of in and contains is the same. |
|
Documentation done. |
I decided against implementing it for floating pointed iotas because comparing floating points is so unreliable.