@@ -35,7 +35,7 @@ consider defining `similar_type` as in the `FieldVector` example.
35
35
yyyy::Float64
36
36
end
37
37
"""
38
- abstract type FieldArray{N, T, D} <: StaticArray{N, T, D} end
38
+ abstract type FieldArray{N,T, D} <: StaticArray{N,T, D} end
39
39
40
40
"""
41
41
abstract FieldMatrix{N1, N2, T} <: FieldArray{Tuple{N1, N2}, 2}
@@ -84,7 +84,7 @@ you may consider using the alternative
84
84
4.0 5.0 6.0;
85
85
7.0 8.0 9.0])
86
86
"""
87
- abstract type FieldMatrix{N1, N2, T} <: FieldArray{Tuple{N1, N2}, T, 2} end
87
+ abstract type FieldMatrix{N1,N2,T} <: FieldArray{Tuple{N1,N2},T, 2} end
88
88
89
89
"""
90
90
abstract FieldVector{N, T} <: FieldArray{Tuple{N}, 1}
@@ -108,11 +108,11 @@ array operations as in the example below.
108
108
109
109
StaticArrays.similar_type(::Type{<:Vec3D}, ::Type{T}, s::Size{(3,)}) where {T} = Vec3D{T}
110
110
"""
111
- abstract type FieldVector{N, T} <: FieldArray{Tuple{N}, T, 1} end
111
+ abstract type FieldVector{N,T} <: FieldArray{Tuple{N},T, 1} end
112
112
113
- @inline (:: Type{FA} )(x:: Tuple ) where {FA <: FieldArray } = construct_type (FA, x)(x... )
113
+ @inline (:: Type{FA} )(x:: Tuple ) where {FA<: FieldArray } = construct_type (FA, x)(x... )
114
114
115
- function construct_type (:: Type{FA} , x) where {FA <: FieldArray }
115
+ function construct_type (:: Type{FA} , x) where {FA<: FieldArray }
116
116
has_size (FA) || error (" $FA has no static size!" )
117
117
length_match_size (FA, x)
118
118
return adapt_eltype (FA, x)
@@ -131,7 +131,7 @@ function similar_type(::Type{A}, ::Type{T}, S::Size) where {T,A<:FieldArray}
131
131
# FieldArrays with parametric `eltype` would be adapted to the new `eltype` automatically.
132
132
A′ = Base. typeintersect (base_type (A), StaticArray{Tuple{Tuple (S)... },T,length (S)})
133
133
# But extra parameters are disallowed here. Also we check `fieldtypes` to make sure the result is valid.
134
- isconcretetype (A′) && fieldtypes (A′) === ntuple (Returns (T) , Val (prod (S))) && return A′
134
+ isconcretetype (A′) && fieldtypes (A′) === ntuple (_ -> T , Val (prod (S))) && return A′
135
135
# Otherwise, we fallback to `S/MArray` based on it's mutability.
136
136
if ismutabletype (A)
137
137
return mutable_similar_type (T, S, length_val (S))
@@ -141,7 +141,12 @@ function similar_type(::Type{A}, ::Type{T}, S::Size) where {T,A<:FieldArray}
141
141
end
142
142
143
143
# return `Union{}` for Union Type. Otherwise return the constructor with no parameters.
144
- @pure base_type (@nospecialize (T:: Type )) = (T′ = Base. unwrap_unionall (T); T′ isa DataType ? T′. name. wrapper : Union{})
145
- if VERSION < v " 1.7"
146
- @pure ismutabletype (@nospecialize (T:: Type )) = (T′ = Base. unwrap_unionall (T); T′ isa DataType && T′. mutable)
144
+ @pure base_type (@nospecialize (T:: Type )) = (T′ = Base. unwrap_unionall (T);
145
+ T′ isa DataType ? T′. name. wrapper : Union{})
146
+ if VERSION < v " 1.8"
147
+ fieldtypes (:: Type{T} ) where {T} = ntuple (i -> fieldtype (T, i), Val (fieldcount (T)))
148
+ @eval @pure function ismutabletype (@nospecialize (T:: Type ))
149
+ T′ = Base. unwrap_unionall (T)
150
+ T′ isa DataType && $ (VERSION < v " 1.7" ? :(T′. mutable) : :(T′. name. flags & 0x2 == 0x2 ))
151
+ end
147
152
end
0 commit comments