考虑以下情况:
struct A <: AbstractArray{Int, 2}
N::Int
end
struct B <: AbstractArray{Int, 2}
A::A
Func
end
...
@inline Base.getindex(A::A, i::Int, j::Int) = begin
@boundscheck (1 <= i <= A.N && 1 <= j <= A.N) || throw(BoundsError())
i - j
end
Base.@propagate_inbounds Base.getindex(B::B, i::Int, j::Int) = begin
B.Func(B.A[i, j])
end
查看文档和一些示例,我确信在执行“@inbounds b[i, j]”(b 是 B 类型的数组)时会消除边界检查。然而,事实并非如此。我错过了什么?