@@ -35,7 +35,7 @@ consider defining `similar_type` as in the `FieldVector` example.
3535 yyyy::Float64
3636 end
3737"""
38- abstract type FieldArray{N, T, D} <: StaticArray{N, T, D} end
38+ abstract type FieldArray{N,T, D} <: StaticArray{N,T, D} end
3939
4040"""
4141 abstract FieldMatrix{N1, N2, T} <: FieldArray{Tuple{N1, N2}, 2}
@@ -84,7 +84,7 @@ you may consider using the alternative
8484 4.0 5.0 6.0;
8585 7.0 8.0 9.0])
8686"""
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
8888
8989"""
9090 abstract FieldVector{N, T} <: FieldArray{Tuple{N}, 1}
@@ -108,11 +108,11 @@ array operations as in the example below.
108108
109109 StaticArrays.similar_type(::Type{<:Vec3D}, ::Type{T}, s::Size{(3,)}) where {T} = Vec3D{T}
110110"""
111- abstract type FieldVector{N, T} <: FieldArray{Tuple{N}, T, 1} end
111+ abstract type FieldVector{N,T} <: FieldArray{Tuple{N},T, 1} end
112112
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... )
114114
115- function construct_type (:: Type{FA} , x) where {FA <: FieldArray }
115+ function construct_type (:: Type{FA} , x) where {FA<: FieldArray }
116116 has_size (FA) || error (" $FA has no static size!" )
117117 length_match_size (FA, x)
118118 return adapt_eltype (FA, x)
@@ -131,7 +131,7 @@ function similar_type(::Type{A}, ::Type{T}, S::Size) where {T,A<:FieldArray}
131131 # FieldArrays with parametric `eltype` would be adapted to the new `eltype` automatically.
132132 A′ = Base. typeintersect (base_type (A), StaticArray{Tuple{Tuple (S)... },T,length (S)})
133133 # 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′
135135 # Otherwise, we fallback to `S/MArray` based on it's mutability.
136136 if ismutabletype (A)
137137 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}
141141end
142142
143143# 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
147152end
0 commit comments