File tree 2 files changed +12
-1
lines changed 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,18 @@ struct SOneTo{n} <: AbstractUnitRange{Int}
8
8
end
9
9
10
10
SOneTo (n:: Int ) = SOneTo {n} ()
11
+ function SOneTo {n} (r:: AbstractUnitRange ) where n
12
+ ((first (r) == 1 ) & (last (r) == n)) && return SOneTo {n} ()
13
+
14
+ errmsg (r) = throw (DimensionMismatch (" $r is inconsistent with SOneTo{$n }" )) # avoid GC frame
15
+ errmsg (r)
16
+ end
11
17
12
18
Base. axes (s:: SOneTo ) = (s,)
13
19
Base. size (s:: SOneTo ) = (length (s),)
14
20
Base. length (s:: SOneTo{n} ) where {n} = n
15
21
16
- function Base. getindex (s:: SOneTo , i:: Int )
22
+ function Base. getindex (s:: SOneTo , i:: Int )
17
23
@boundscheck checkbounds (s, i)
18
24
return i
19
25
end
Original file line number Diff line number Diff line change 189
189
b = StaticArrays. SOneTo {2} ()
190
190
@test @inferred (promote (a, b)) === (a, Base. OneTo (2 ))
191
191
@test @inferred (promote (b, a)) === (Base. OneTo (2 ), a)
192
+
193
+ @test StaticArrays. SOneTo {2} (1 : 2 ) === StaticArrays. SOneTo {2} ()
194
+ @test convert (StaticArrays. SOneTo{2 }, 1 : 2 ) === StaticArrays. SOneTo {2} ()
195
+ @test_throws DimensionMismatch StaticArrays. SOneTo {2} (1 : 3 )
196
+ @test_throws DimensionMismatch StaticArrays. SOneTo {2} (1 : 1 )
192
197
end
193
198
end
You can’t perform that action at this time.
0 commit comments