I tried to create a type alias of Vararg
(with a specific number of arguments) as follows.
const FormArgs{K,D} = Vararg{StaticVector{D}, K}
However, if I try FormArgs{3,2}
it does not produce Vararg{StaticVector{2},3}
and an error is thrown. I think that is because Vararg
is not really a DataType
. Thus, its behavior differs from the similar
const FormTuple{K,D} = NTuple{K, StaticVector{D}}
which works as expected.
However, if you try to use
f(args::FormTuple{K,D}) where {K,D} = ... # function definition using args[1] ... args[K]
you are forced to pass arguments to f
wrapped in a tuple. In practice, I think you can work around the issue with a helper method
f(args...) = f(args)
but I am wondering if there is a less hacky approach.
Edit: Using f(args...) = f(args)
as above will result in infinite recursion of f
into itself if the wrong number of arguments is passed. Better not do that.
In practice, I am using this in a callable type that is parameterized by a known number of arguments, so the pattern is OK:
(::MyCallable{K})(x::FormTuple{K,D}}) where {K,D} = ...
(instance::MyCallable{K})(x::Vararg{Any,K}) where {K} = instance(x) # defer to method above
A MethodError
is thrown if the wrong number of arguments are used.