How to build data structures on Arrays without specifying the array implementation?

Having an abstract field type like that will significantly harm performance. Instead, you can do:

struct Foo{T, V <: AbstractVector{T}}
  v::V 
end

if you want the element type T to be an explicit type parameter.

Also note that this isn’t strictly necessary. You can use @stevengj’s suggestion and implement Base.eltype for your Container with no loss of performance or expressiveness.

4 Likes