Why doesn't empty call similar?

The docstring for empty states that


  empty(v::AbstractVector, [eltype])

  Create an empty vector similar to v, optionally changing the eltype.

The method, though, is defined as

empty(a::AbstractVector{T}, ::Type{U}=T) where {T,U} = Vector{U}()

This works, but I wonder why it doesn’t call similar(a, U, 0) instead? Wouldn’t this be more in line with the docstring? And it should fall back to a Vector anyway, if no specializations are available.

3 Likes

I’m not sure; seems like a good idea to use similar here.