I want to create a type (a fixed size array) that is parameterized on an
Int but does not have exactly the same number of components as the
parameter. This does not work however:
# Works:
immutable Vec2{N, T}
v::NTuple{N, T}
end
Vec2{3, Float64}((1.0,2.0,3.0))
# Vec2{3,Float64}((1.0,2.0,3.0))
# Sad times
immutable Vec2{N, T}
v::NTuple{N+1, T}
end
ERROR: MethodError: `+` has no method matching +(::TypeVar, ::Int64)
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...)
+(::Int64, ::Int64)
+(::Complex{Bool}, ::Real)
...
Is there anyway to do something like this? It is possible in C++ using
templates for example.
My application is for writing a library for tensors (to be used in solid
mechanics) on top of the FixedSizeArrays package and I want the tensors to
be parameterized on the rank and dimension which means that the number of
components is f(rank, dimension) where f is some function Int x Int -> Int.
Best regards,
Kristoffer Carlsson