@@ -61,6 +61,16 @@ struct StaticInt{N} <: StaticInteger{N}
6161 StaticInt (:: Val{N} ) where {N} = StaticInt (N)
6262end
6363
64+ """
65+ IntType(x::Integer) -> Union{Int,StaticInt}
66+
67+ `IntType` is a union of `Int` and `StaticInt`. As a function, it ensures that `x` one of the
68+ two.
69+ """
70+ const IntType = Union{StaticInt, Int}
71+ IntType (x:: Integer ) = Int (x)
72+ IntType (@nospecialize x:: Union{Int, StaticInt} ) = x
73+
6474include (" float.jl" )
6575
6676const StaticNumber{N} = Union{StaticInt{N}, StaticBool{N}, StaticFloat64{N}}
@@ -260,6 +270,36 @@ _static_promote(::Nothing, ::Nothing) = nothing
260270_static_promote (x, :: Nothing ) = x
261271_static_promote (:: Nothing , y) = y
262272
273+ """
274+ static_promote(x::AbstractRange{<:Integer}, y::AbstractRange{<:Integer})
275+
276+ A type stable method for combining two equal ranges into a new range that preserves static
277+ parameters. Throws an error if `x != y`.
278+
279+ # Examples
280+
281+ ```julia
282+ julia> static_promote(static(1):10, 1:static(10))
283+ static(1):static(10)
284+
285+ julia> static_promote(1:2:9, static(1):static(2):static(9))
286+ static(1):static(2):static(9)
287+ ```
288+ """
289+ Base. @propagate_inbounds @inline function static_promote (x:: AbstractUnitRange{<:Integer} ,
290+ y:: AbstractUnitRange{<:Integer} )
291+ fst = static_promote (static_first (x), static_first (y))
292+ lst = static_promote (static_last (x), static_last (y))
293+ return OptionallyStaticUnitRange (fst, lst)
294+ end
295+ Base. @propagate_inbounds @inline function static_promote (x:: AbstractRange{<:Integer} ,
296+ y:: AbstractRange{<:Integer} )
297+ fst = static_promote (static_first (x), static_first (y))
298+ stp = static_promote (static_step (x), static_step (y))
299+ lst = static_promote (static_last (x), static_last (y))
300+ return _OptionallyStaticStepRange (fst, stp, lst)
301+ end
302+
263303Base. @propagate_inbounds function _promote_shape (a:: Tuple{A, Vararg{Any}} ,
264304 b:: Tuple{B, Vararg{Any}} ) where {A, B}
265305 (static_promote (getfield (a, 1 ), getfield (b, 1 )),
@@ -879,4 +919,6 @@ function Base.show(io::IO, m::MIME"text/plain", @nospecialize(x::NDIndex))
879919 nothing
880920end
881921
922+ include (" ranges.jl" )
923+
882924end
0 commit comments