@@ -3,16 +3,18 @@ module CloseOpenIntervals
3
3
using Static: StaticInt, Zero, One
4
4
export CloseOpen, SafeCloseOpen
5
5
6
- abstract type AbstractCloseOpen{L <: Union{Int,StaticInt} , U <: Union{Int,StaticInt} } <: AbstractUnitRange{Int} end
6
+ const IntegerType = Union{Integer,StaticInt}
7
+
8
+ abstract type AbstractCloseOpen{L <: IntegerType , U <: IntegerType } <: AbstractUnitRange{Int} end
7
9
for T ∈ (:CloseOpen ,:SafeCloseOpen )
8
10
@eval begin
9
- struct $ T{L <: Union{Int,StaticInt} , U <: Union{Int,StaticInt} } <: AbstractCloseOpen{L,U}
11
+ struct $ T{L <: IntegerType , U <: IntegerType } <: AbstractCloseOpen{L,U}
10
12
start:: L
11
13
upper:: U
12
- @inline $ T {L,U} (l:: L ,u:: U ) where {L <: Union{Int,StaticInt} , U <: Union{Int,StaticInt} } = new {L,U} (l,u)
14
+ @inline $ T {L,U} (l:: L ,u:: U ) where {L <: IntegerType , U <: IntegerType } = new {L,U} (l,u)
13
15
end
14
16
@inline $ T (s:: S , u:: U ) where {S,U} = $ T {S,U} (s, u)
15
- @inline $ T (len:: T ) where {T<: Union{Int,StaticInt} } = $ T {Zero,T} (Zero (), len)
17
+ @inline $ T (len:: T ) where {T<: IntegerType } = $ T {Zero,T} (Zero (), len)
16
18
end
17
19
end
18
20
@@ -62,14 +64,14 @@ SafeCloseOpen
62
64
@inline Base. first (r:: AbstractCloseOpen ) = getfield (r,:start )
63
65
@inline Base. first (r:: AbstractCloseOpen{StaticInt{F}} ) where {F} = F
64
66
@inline Base. step (:: AbstractCloseOpen ) = 1
65
- @inline Base. last (r:: AbstractCloseOpen{<:Union{Int,StaticInt} ,I} ) where {I} = getfield (r,:upper ) - 1
66
- @inline Base. last (r:: AbstractCloseOpen{<:Union{Int,StaticInt} ,StaticInt{L}} ) where {L} = L - 1
67
+ @inline Base. last (r:: AbstractCloseOpen{<:IntegerType ,I} ) where {I} = getfield (r,:upper ) - 1
68
+ @inline Base. last (r:: AbstractCloseOpen{<:IntegerType ,StaticInt{L}} ) where {L} = L - 1
67
69
@inline Base. length (r:: AbstractCloseOpen ) = getfield (r,:upper ) - getfield (r,:start )
68
70
@inline Base. length (r:: AbstractCloseOpen{Zero} ) = getfield (r,:upper )
69
71
70
72
@inline Base. iterate (r:: CloseOpen ) = (i = Int (first (r)); (i, i))
71
73
@inline Base. iterate (r:: SafeCloseOpen ) = (i = Int (first (r)); i ≥ getfield (r, :upper ) ? nothing : (i, i))
72
- @inline Base. iterate (r:: AbstractCloseOpen , i:: Union{Int,StaticInt} ) = (i += one (i)) ≥ getfield (r, :upper ) ? nothing : (i, i)
74
+ @inline Base. iterate (r:: AbstractCloseOpen , i:: IntegerType ) = (i += one (i)) ≥ getfield (r, :upper ) ? nothing : (i, i)
73
75
74
76
import ArrayInterface
75
77
ArrayInterface. known_first (:: Type{<:AbstractCloseOpen{StaticInt{F}}} ) where {F} = F
0 commit comments