-
-
Notifications
You must be signed in to change notification settings - Fork 739
Issue 6447 & 10762: support user-defined types in iota() #2895
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
Conversation
Add Params:. Use Returns:. Include previously-overlooked overload that broke a ddoc'd unittest.
Maybe it's a bit of an overkill, but have you considered using |
Apart from that, LGTM. I especially find the documentation more readable now 👍 |
I did consider using |
One alternative is to use |
That's a good point. Though, I think that if your are using custom floats you may accumulate a larger error with this version, than with specialized one, which directly returns
OK, let's use |
Well, the idea is that this is just the most general, basic implementation. Later on, the plan is to extend it to take advantage of types that provide multiplication -- not only that will eliminate accumulation of roundoff errors, it will also allow us to return a random-access range instead of just an input range. |
There's also the case of detecting when a type supports |
if (!isIntegral!(CommonType!(B, E)) && | ||
!isFloatingPoint!(CommonType!(B, E)) && | ||
!isPointer!(CommonType!(B, E)) && | ||
is(typeof(++B.init)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this spells trouble if B.init
is an rvalue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was a pull request for lvalueInit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which PR was that?
what's with the failures? |
No idea, I saw outbuffer failures on somebody else's unrelated PR too. Some kind of intermittent bug that somehow slipped into the code maybe? |
Fixed to use ref. |
That was #2902 |
Ah, so that's what it was. |
The autotester is now green. Anything else that needs to be fixed? |
OK, that's a good first step. I keep on thinking we should define abstract algebra paraphernalia like |
Auto-merge toggled on |
Issue 6447 & 10762: support user-defined types in iota()
@andralex The problem with that is, some things can't be tested at compile-time, e.g., |
If we don't stick to abstract algebra, though, I suppose we could usefully have templates like |
Although I'm not necessarily arguing for their inclusion, they would be useful for std.range.enumerate too (#1866). |
Hmm. Maybe it's worth adding, then. If nothing else, it would make the sig constraints more readable... |
Fixes: https://issues.dlang.org/show_bug.cgi?id=6447
Partially fixes: https://issues.dlang.org/show_bug.cgi?id=10762
Basically, as long as a type supports comparison via
<
and incrementing via++
,iota
should work.This is an initial stab at issue 10762; it provides the baseline for the most general user-defined types, so the returned range for non-built-in types will only be input ranges. Subsequent PRs will gradually refine this, e.g., to support random access if
x + y*k
is a supported operation in the underlying type.