diff --git a/src/SOneTo.jl b/src/SOneTo.jl index b3a207b8..3a59ae65 100644 --- a/src/SOneTo.jl +++ b/src/SOneTo.jl @@ -4,7 +4,14 @@ Return a statically-sized `AbstractUnitRange` starting at `1`, functioning as the `axes` of a `StaticArray`. """ -struct SOneTo{n} <: AbstractUnitRange{Int} +SOneTo + +if isdefined(Base, :AbstractOneTo) + struct SOneTo{n} <: Base.AbstractOneTo{Int} + end +else + struct SOneTo{n} <: AbstractUnitRange{Int} + end end SOneTo(n::Int) = SOneTo{n}() diff --git a/src/abstractarray.jl b/src/abstractarray.jl index 383d382a..898a5334 100644 --- a/src/abstractarray.jl +++ b/src/abstractarray.jl @@ -142,8 +142,13 @@ const HeterogeneousBaseShape = Union{Integer, Base.OneTo} const HeterogeneousShape = Union{HeterogeneousBaseShape, SOneTo} const HeterogeneousShapeTuple = Tuple{Vararg{HeterogeneousShape}} -similar(A::AbstractArray, ::Type{T}, shape::HeterogeneousShapeTuple) where {T} = similar(A, T, homogenize_shape(shape)) -similar(::Type{A}, shape::HeterogeneousShapeTuple) where {A<:AbstractArray} = similar(A, homogenize_shape(shape)) +if isdefined(Base, :AbstractOneTo) + similar(A::AbstractArray, ::Type{T}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {T} = similar(A, T, homogenize_shape(shape)) + similar(::Type{A}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray} = similar(A, homogenize_shape(shape)) +else + similar(A::AbstractArray, ::Type{T}, shape::HeterogeneousShapeTuple) where {T} = similar(A, T, homogenize_shape(shape)) + similar(::Type{A}, shape::HeterogeneousShapeTuple) where {A<:AbstractArray} = similar(A, homogenize_shape(shape)) +end # Use an Array for StaticArrays if we don't have a statically-known size similar(::Type{A}, shape::Tuple{Int, Vararg{Int}}) where {A<:StaticArray} = Array{eltype(A)}(undef, shape)