-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Deprecate first() and last() on empty ranges #25385
Conversation
This will allow throwing an error, for consistency with other AbstractArrays. Introduce the rangestart() and rangestop() functions instead.
de4d005
to
2c29e08
Compare
A definition like |
Addendum: in that particular case it should probably still call I still don't love this change though. It seems like we're saying, "if you call |
This might be a good place for properties: make In other words my proposal is very similar to this change but you write |
That was addressed in the OP. |
Question from triage: were any bugs revealed by this PR? |
@StefanKarpinski I haven't found bugs. Though the kind of bugs this change would uncover are cases where However, the PR highlights that the special behavior of julia> first(CartesianIndices(1:0, 3:0))
CartesianIndex(1, 3)
julia> collect(CartesianIndices(1:0, 3:0))
0×0 Array{CartesianIndex{2},2} See also below for a possible issue related to
@JeffBezanson Using You're right that this pattern wouldn't work if
I have to admit it's not the sexiest PR ever. OTOH it's really weird to break the |
These aren't equivalent situations. Currently, the issue is that |
@@ -682,7 +682,7 @@ copyto!(dest::AbstractArray, src::AbstractArray) = | |||
|
|||
function copyto!(::IndexStyle, dest::AbstractArray, ::IndexStyle, src::AbstractArray) | |||
destinds, srcinds = linearindices(dest), linearindices(src) | |||
isempty(srcinds) || (first(srcinds) ∈ destinds && last(srcinds) ∈ destinds) || | |||
isempty(srcinds) || (rangestart(srcinds) ∈ destinds && rangestop(srcinds) ∈ destinds) || |
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.
Since there is an isempty
check, I think this case can be left alone.
Looking over the changes again, I think I'd like this a lot better if On the triage call @mbauman suggested changing the functions with
That would also be an improvement. One interesting case is getting a pointer to the "first element" of an empty array. Using |
The problem with that is that the majority of the uses are with
I've tried that, but it doesn't always work. For example, in |
#22354 is closed |
This will allow throwing an error, for consistency with other
AbstractArray
s.Introduce the
rangestart
andrangestop
functions instead.Fixes #22354.
This is RFC because two issues need to be discussed (apart from missing docs and FIXME):
r.start
andr.stop
instead of addingrangestart
andrangestop
functions. I think this use for ranges has been considered when discussing the feature, but since that would be one of the first times it would be used in Base, I'd rather check that people support it before adopting that approach.rangestart
andrangestop
accept integers and return them, just likefirst
andlast
do. See the second commit to have a list of the few places where it's needed. Unfortunately, that doesn't play well with using field overloading, except if we are OK with things like1.start
returning1
.