Skip to content

Commit

Permalink
Add CartesianIndices(()) for Ref getindex and setindex!
Browse files Browse the repository at this point in the history
  • Loading branch information
jmert committed Dec 31, 2019
1 parent 13d1bd4 commit cf5a16e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1802,4 +1802,6 @@ function _sortslices(A::AbstractArray, d::Val{dims}; kws...) where dims
end

getindex(b::Ref, ::CartesianIndex{0}) = getindex(b)
getindex(b::Ref, ::CartesianIndices{0,Tuple{}}) = getindex(b)
setindex!(b::Ref, x, ::CartesianIndex{0}) = setindex!(b, x)
setindex!(b::Ref, x, ::CartesianIndices{0,Tuple{}}) = setindex!(b, x)
3 changes: 3 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,11 @@ end
@testset "getindex and setindex! for Ref" begin
for x in [Ref(1), Ref([1,2,3], 1)]
@test getindex(x) == getindex(x, CartesianIndex()) == 1
@test getindex(x) == getindex(x, CartesianIndices(())) == 1
x[CartesianIndex()] = 10
@test getindex(x) == getindex(x, CartesianIndex()) == 10
x[CartesianIndices(())] = 11
@test getindex(x) == getindex(x, CartesianIndices(())) == 11
end
end

Expand Down

0 comments on commit cf5a16e

Please sign in to comment.