Is there a package for a non-allocating representation of a single-element vector? I am basically thinking of the equivalent of
struct OneElementVector{T} <: AbstractVector{T}
x::T
end
Base.size(v::OneElementVector) = (1, )
Base.getindex(v::OneElementVector, i::Int) = i == 1 ? v.x : throw(BoundsError(v, i))
Base.RefValue
is not the same because it requires no index,while StaticArrays.SVector(x)
is overkill.