Confused with type definition

I am kinda surprised nobody mentioned Lazy.jl and its macro @forward.

Basically you can do:

import Base: length, getindex, setindex
using Lazy: @forward

struct MyVec <: AbstractVector{Float64}
  v::Vector{Float64} # same as Array{Float64, 1}
end

@forward MyVec.v Base.size, Base.getindex, Base.setindex!

For all function you just delegate to the field.

13 Likes