Tuple with conditional entries

In that case, performance doesn’t matter since it is happening at compile time, so I would just do it as an array and then convert back to a tuple, e.g.:

@generated function Base.push!(records::MyRecord{R1,R2,R3}, var1, var2, var3) where {R1,R2,R3}
    rowexpr = Tuple([:var1, :var2, :var3][[R1,R2,R3]])
    return quote
        row = $rowexpr
        push!(records.data, row)
    end
end

Arrays are easier for these kinds of manipulations.

2 Likes