I’m writing a macro to generate structs. I would like to substitute different parameterized types as a structure element. How can I achieve this? Below is the example code that does not work:
for (Tp, matTp) in ((:TranslationMatrix, :AnisotropicScaleMatrix),
(UpperTriangular{:T, SMatrix{N, N, T, L}}, SMatrix{N, N, T, L}))
@eval begin
struct $Tp{N,T,L} <: StaticMatrix{N,N,T}
mat::$matTp
$Tp{N,T,L}(x::AbstractArray) where {N,T,L} = new{N,T,L}(convert(SMatrix{N,N,T,L}, x))
# fixes #49 ambiguity introduced in StaticArrays 0.6.5
$Tp{N,T,L}(x::StaticArray) where {N,T,L} = new{N,T,L}(convert(SMatrix{N,N,T,L}, x))
end
@inline function $Tp(t::Tuple)
n = sqrt(length(t))
if !isinteger(n)
throw(DimensionMismatch("The length of input tuple $(t) must be square number."))
end
N = Int(n)
$Tp(SMatrix{N,N}(t))
end
@inline $Tp{N}(t::Tuple) where {N} = $Tp(SArray{Tuple{N,N}}(t))
@inline $Tp{N,T}(t::Tuple) where {N,T} = $Tp(SArray{Tuple{N,N},T}(t))
@inline $Tp{N,T,L}(t::Tuple) where {N,T,L} = $Tp(SArray{Tuple{N,N},T}(t))
end
end