struct ZeroPaddedVector{T, V <: AbstractVector{T}} <: AbstractVector{T} vec :: V len :: Int end # https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array Base.size(p::ZeroPaddedVector) = (p.len, ) Base.getindex(p::ZeroPaddedVector, i::Int) = checkbounds(Bool, p.vec, i) ? p.vec[i] : zero(eltype(p)) ZeroPaddedVector(rand(7), 10)