Skip to content

Commit e98f5b3

Browse files
committed
SOneTo subtypes AbstractOneTo
1 parent e23a2f5 commit e98f5b3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/SOneTo.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
Return a statically-sized `AbstractUnitRange` starting at `1`, functioning as the `axes` of
55
a `StaticArray`.
66
"""
7-
struct SOneTo{n} <: AbstractUnitRange{Int}
7+
SOneTo
8+
9+
if isdefined(Base, :AbstractOneTo)
10+
struct SOneTo{n} <: Base.AbstractOneTo{Int}
11+
end
12+
else
13+
struct SOneTo{n} <: AbstractUnitRange{Int}
14+
end
815
end
916

1017
SOneTo(n::Int) = SOneTo{n}()

src/abstractarray.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,13 @@ const HeterogeneousBaseShape = Union{Integer, Base.OneTo}
142142
const HeterogeneousShape = Union{HeterogeneousBaseShape, SOneTo}
143143
const HeterogeneousShapeTuple = Tuple{Vararg{HeterogeneousShape}}
144144

145-
similar(A::AbstractArray, ::Type{T}, shape::HeterogeneousShapeTuple) where {T} = similar(A, T, homogenize_shape(shape))
146-
similar(::Type{A}, shape::HeterogeneousShapeTuple) where {A<:AbstractArray} = similar(A, homogenize_shape(shape))
145+
if isdefined(Base, :AbstractOneTo)
146+
similar(A::AbstractArray, ::Type{T}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {T} = similar(A, T, homogenize_shape(shape))
147+
similar(::Type{A}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray} = similar(A, homogenize_shape(shape))
148+
else
149+
similar(A::AbstractArray, ::Type{T}, shape::HeterogeneousShapeTuple) where {T} = similar(A, T, homogenize_shape(shape))
150+
similar(::Type{A}, shape::HeterogeneousShapeTuple) where {A<:AbstractArray} = similar(A, homogenize_shape(shape))
151+
end
147152
# Use an Array for StaticArrays if we don't have a statically-known size
148153
similar(::Type{A}, shape::Tuple{Int, Vararg{Int}}) where {A<:StaticArray} = Array{eltype(A)}(undef, shape)
149154

0 commit comments

Comments
 (0)