Skip to content

Commit 2c8d82f

Browse files
authored
Merge pull request #586 from tribut/general-indexing-checkbounds
Allow using static arrays as index for views
2 parents 608736e + a33080d commit 2c8d82f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/indexing.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,11 @@ end
346346
end
347347
end
348348
end
349+
350+
# checkindex
351+
352+
Base.checkindex(B::Type{Bool}, inds::AbstractUnitRange, i::StaticIndexing{T}) where T = Base.checkindex(B, inds, unwrap(i))
353+
354+
# unsafe_view
355+
356+
Base.unsafe_view(A::AbstractArray, i::StaticIndexing{T}) where T = Base.unsafe_view(A, unwrap(i))

test/indexing.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,10 @@ using StaticArrays, Test
181181
@test (zeros(0,2)[SVector{0,Int}(),SVector(1)] = 0) == 0
182182
@test (zeros(2,0)[SVector(1),SVector{0,Int}()] = 0) == 0
183183
end
184+
185+
@testset "Using SArray as index for view" begin
186+
a = collect(11:20)
187+
@test view(a, SVector(1,2,3)) == [11,12,13]
188+
@test_throws BoundsError view(a, SVector(1,11,3))
189+
end
184190
end

0 commit comments

Comments
 (0)