What is the canonical way of extracting the parameters of a Tuple
, and verifying that it has fixed length? Using advice I got in another topic, I am now using
"""
extract_Tuple_fixed(T)
Extract the parameters of a Tuple and verify that they have a fixed length.
"""
function extract_Tuple_fixed(T::Type{<: Tuple})
p = tuple(T.parameters...)
@assert !(p[end] <: Vararg) "Not a tuple of fixed length."
p
end
which works:
julia> extract_Tuple_fixed(Tuple{Int,Int})
(Int64, Int64)
julia> extract_Tuple_fixed(NTuple{4,Int})
(Int64, Int64, Int64, Int64)
julia> extract_Tuple_fixed(Tuple{Int,Vararg{Int}})
ERROR: AssertionError: Not a tuple of fixed length.
Stacktrace:
[1] extract_Tuple_fixed(::Type{Tuple{Int64,Vararg{Int64,N} where N}}) at ./REPL[83
]:3
but I am wondering if there is something neater, eg with a parametric function-template
this_does_not_work(::Type{Tuple{T...}}) = T