Skip to content

Commit e24e1d8

Browse files
andreasnoackandyferris
authored andcommitted
Use new inner constructor and type declaration syntax (#107)
Use new inner constructor and type declaration syntax and use *Compat.jl* to support v0.5 and v0.6
1 parent 05c2cb7 commit e24e1d8

20 files changed

+92
-90
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
julia 0.5
2+
Compat 0.19.0

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ environment:
22
matrix:
33
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
44
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
5-
# - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
6-
# - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
5+
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
6+
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
77

88
branches:
99
only:

src/FieldVector.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For example:
1515
z::Float64
1616
end
1717
"""
18-
abstract FieldVector{T} <: StaticVector{T}
18+
@compat abstract type FieldVector{T} <: StaticVector{T} end
1919

2020
# Is this a good idea?? Should people just define constructors that accept tuples?
2121
@inline (::Type{FV}){FV<:FieldVector}(x::Tuple) = FV(x...)

src/ImmutableArrays.jl

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
module ImmutableArrays
22

33
using ..StaticArrays
4-
5-
typealias Vector1{T} SVector{1,T}
6-
typealias Vector2{T} SVector{2,T}
7-
typealias Vector3{T} SVector{3,T}
8-
typealias Vector4{T} SVector{4,T}
9-
10-
typealias Matrix1x1{T} SMatrix{1,1,T,1}
11-
typealias Matrix1x2{T} SMatrix{1,2,T,2}
12-
typealias Matrix1x3{T} SMatrix{1,3,T,3}
13-
typealias Matrix1x4{T} SMatrix{1,4,T,4}
14-
15-
typealias Matrix2x1{T} SMatrix{2,1,T,2}
16-
typealias Matrix2x2{T} SMatrix{2,2,T,4}
17-
typealias Matrix2x3{T} SMatrix{2,3,T,6}
18-
typealias Matrix2x4{T} SMatrix{2,4,T,8}
19-
20-
typealias Matrix3x1{T} SMatrix{3,1,T,3}
21-
typealias Matrix3x2{T} SMatrix{3,2,T,6}
22-
typealias Matrix3x3{T} SMatrix{3,3,T,9}
23-
typealias Matrix3x4{T} SMatrix{3,4,T,12}
24-
25-
typealias Matrix4x1{T} SMatrix{4,1,T,4}
26-
typealias Matrix4x2{T} SMatrix{4,2,T,8}
27-
typealias Matrix4x3{T} SMatrix{4,3,T,12}
28-
typealias Matrix4x4{T} SMatrix{4,4,T,16}
4+
using Compat
5+
6+
@compat Vector1{T} = SVector{1,T}
7+
@compat Vector2{T} = SVector{2,T}
8+
@compat Vector3{T} = SVector{3,T}
9+
@compat Vector4{T} = SVector{4,T}
10+
11+
@compat Matrix1x1{T} = SMatrix{1,1,T,1}
12+
@compat Matrix1x2{T} = SMatrix{1,2,T,2}
13+
@compat Matrix1x3{T} = SMatrix{1,3,T,3}
14+
@compat Matrix1x4{T} = SMatrix{1,4,T,4}
15+
16+
@compat Matrix2x1{T} = SMatrix{2,1,T,2}
17+
@compat Matrix2x2{T} = SMatrix{2,2,T,4}
18+
@compat Matrix2x3{T} = SMatrix{2,3,T,6}
19+
@compat Matrix2x4{T} = SMatrix{2,4,T,8}
20+
21+
@compat Matrix3x1{T} = SMatrix{3,1,T,3}
22+
@compat Matrix3x2{T} = SMatrix{3,2,T,6}
23+
@compat Matrix3x3{T} = SMatrix{3,3,T,9}
24+
@compat Matrix3x4{T} = SMatrix{3,4,T,12}
25+
26+
@compat Matrix4x1{T} = SMatrix{4,1,T,4}
27+
@compat Matrix4x2{T} = SMatrix{4,2,T,8}
28+
@compat Matrix4x3{T} = SMatrix{4,3,T,12}
29+
@compat Matrix4x4{T} = SMatrix{4,4,T,16}
2930

3031
export Vector1, Vector2, Vector3, Vector4,
3132
Matrix1x1, Matrix1x2, Matrix1x3, Matrix1x4,

src/MArray.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ compiler (the element type may optionally also be specified).
1919
type MArray{Size, T, N, L} <: StaticArray{T, N}
2020
data::NTuple{L,T}
2121

22-
function MArray(x::NTuple{L,T})
22+
function (::Type{MArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,T})
2323
check_marray_parameters(Val{Size}, T, Val{N}, Val{L})
24-
new(x)
24+
new{Size,T,N,L}(x)
2525
end
2626

27-
function MArray(x::NTuple{L,Any})
27+
function (::Type{MArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,Any})
2828
check_marray_parameters(Val{Size}, T, Val{N}, Val{L})
29-
new(convert_ntuple(T, x))
29+
new{Size,T,N,L}(convert_ntuple(T, x))
3030
end
3131

32-
function MArray()
32+
function (::Type{MArray{Size,T,N,L}}){Size,T,N,L}()
3333
check_marray_parameters(Val{Size}, T, Val{N}, Val{L})
34-
new()
34+
new{Size,T,N,L}()
3535
end
3636
end
3737

src/MMatrix.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ unknown to the compiler (the element type may optionally also be specified).
1818
type MMatrix{S1, S2, T, L} <: StaticMatrix{T}
1919
data::NTuple{L, T}
2020

21-
function MMatrix(d::NTuple{L,T})
21+
function (::Type{MMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,T})
2222
check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L})
23-
new(d)
23+
new{S1,S2,T,L}(d)
2424
end
2525

26-
function MMatrix(d::NTuple{L,Any})
26+
function (::Type{MMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,Any})
2727
check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L})
28-
new(convert_ntuple(T, d))
28+
new{S1,S2,T,L}(convert_ntuple(T, d))
2929
end
3030

31-
function MMatrix()
31+
function (::Type{MMatrix{S1,S2,T,L}}){S1,S2,T,L}()
3232
check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L})
33-
new()
33+
new{S1,S2,T,L}()
3434
end
3535
end
3636

src/MVector.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ compiler (the element type may optionally also be specified).
1717
type MVector{S, T} <: StaticVector{T}
1818
data::NTuple{S, T}
1919

20-
function MVector(in::NTuple{S, T})
21-
new(in)
20+
function (::Type{MVector{S,T}}){S,T}(in::NTuple{S, T})
21+
new{S,T}(in)
2222
end
2323

24-
function MVector(in::NTuple{S, Any})
25-
new(convert_ntuple(T,in))
24+
function (::Type{MVector{S,T}}){S,T}(in::NTuple{S, Any})
25+
new{S,T}(convert_ntuple(T,in))
2626
end
2727

28-
function MVector(in::T)
29-
new((in,))
28+
function (::Type{MVector{S,T}}){S,T}(in::T)
29+
new{S,T}((in,))
3030
end
3131

32-
function MVector()
33-
new()
32+
function (::Type{MVector{S,T}}){S,T}()
33+
new{S,T}()
3434
end
3535
end
3636

src/SArray.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ compiler (the element type may optionally also be specified).
1818
immutable SArray{Size, T, N, L} <: StaticArray{T, N}
1919
data::NTuple{L,T}
2020

21-
function SArray(x::NTuple{L,T})
21+
function (::Type{SArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,T})
2222
check_sarray_parameters(Val{Size}, T, Val{N}, Val{L})
23-
new(x)
23+
new{Size,T,N,L}(x)
2424
end
2525

26-
function SArray(x::NTuple{L,Any})
26+
function (::Type{SArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,Any})
2727
check_sarray_parameters(Val{Size}, T, Val{N}, Val{L})
28-
new(convert_ntuple(T, x))
28+
new{Size,T,N,L}(convert_ntuple(T, x))
2929
end
3030
end
3131

src/SMatrix.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ unknown to the compiler (the element type may optionally also be specified).
1717
immutable SMatrix{S1, S2, T, L} <: StaticMatrix{T}
1818
data::NTuple{L, T}
1919

20-
function SMatrix(d::NTuple{L,T})
20+
function (::Type{SMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,T})
2121
check_smatrix_params(Val{S1}, Val{S2}, T, Val{L})
22-
new(d)
22+
new{S1,S2,T,L}(d)
2323
end
2424

25-
function SMatrix(d::NTuple{L,Any})
25+
function (::Type{SMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,Any})
2626
check_smatrix_params(Val{S1}, Val{S2}, T, Val{L})
27-
new(convert_ntuple(T, d))
27+
new{S1,S2,T,L}(convert_ntuple(T, d))
2828
end
2929
end
3030

@@ -66,7 +66,7 @@ end
6666
SMatrix{S1, S2, $T, L}(x)
6767
end
6868
end
69-
typealias SMatrixNoType{S1, S2, L, T} SMatrix{S1, S2, T, L}
69+
@compat SMatrixNoType{S1, S2, L, T} = SMatrix{S1, S2, T, L}
7070
@generated function (::Type{SMatrixNoType{S1, S2, L}}){S1,S2,L}(x::NTuple{L,Any})
7171
T = promote_tuple_eltype(x)
7272
return quote

src/SVector.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ compiler (the element type may optionally also be specified).
1616
immutable SVector{S, T} <: StaticVector{T}
1717
data::NTuple{S, T}
1818

19-
function SVector(x::NTuple{S,T})
20-
new(x)
19+
function (::Type{SVector{S, T}}){S, T}(x::NTuple{S,T})
20+
new{S, T}(x)
2121
end
2222

23-
function SVector(x::NTuple{S,Any})
24-
new(convert_ntuple(T, x))
23+
function (::Type{SVector{S, T}}){S, T}(x::NTuple{S,Any})
24+
new{S, T}(convert_ntuple(T, x))
2525
end
2626
end
2727

0 commit comments

Comments
 (0)