Skip to content

Commit 5fac768

Browse files
authored
add fieldnames and fieldtypes for 1.0 compat
1 parent 15b5add commit 5fac768

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/compat.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
if VERSION < v"1.2"
22
Base.getproperty(x::Tuple, f::Int) = getfield(x, f)
33
end
4+
5+
if VERSION < v"1.1"
6+
# Note: these are actually *better* than the ones in julia 1.1, 1.2, 1.3,and 1.4
7+
# See: https://github.com/JuliaLang/julia/issues/34292
8+
function fieldtypes(::Type{T}) where T
9+
if @generated
10+
ntuple(i -> fieldtype(T, i), fieldcount(T))
11+
else
12+
ntuple(i -> fieldtype(T, i), fieldcount(T))
13+
end
14+
end
15+
16+
function fieldnames(::Type{T}) where T
17+
if @generated
18+
ntuple(i -> fieldname(T, i), fieldcount(T))
19+
else
20+
ntuple(i -> fieldname(T, i), fieldcount(T))
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)