Skip to content

Commit 664ea95

Browse files
authored
Merge pull request #101 from Tokazama/static-print
Prettier StaticInt print
2 parents 6d18933 + ed4128a commit 664ea95

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "2.14.7"
3+
version = "2.14.8"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/ranges.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,15 @@ end
464464
lst = _try_static(static_last(x), static_last(y))
465465
return Base.Slice(OptionallyStaticUnitRange(fst, lst))
466466
end
467+
468+
function Base.show(io::IO, r::OptionallyStaticRange)
469+
print(io, first(r))
470+
if known_step(r) === 1
471+
print(io, ":")
472+
else
473+
print(io, ":")
474+
print(io, step(r))
475+
print(io, ":")
476+
end
477+
print(io, last(r))
478+
end

src/static.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
"""
3+
StaticInt(N::Int) -> StaticInt{N}()
4+
35
A statically sized `Int`.
46
Use `StaticInt(N)` instead of `Val(N)` when you want it to behave like a number.
57
"""
68
struct StaticInt{N} <: Integer
79
StaticInt{N}() where {N} = new{N::Int}()
810
end
911

12+
Base.show(io::IO, ::StaticInt{N}) where {N} = print(io, "Static($N)")
13+
1014
const Zero = StaticInt{0}
1115
const One = StaticInt{1}
1216

0 commit comments

Comments
 (0)