Undef for non-arrays

Do we have something similar to undef for non-arrays? Wishful thinking:

f() = a::Tuple{Int, Int} where T = 5, undef 

Could you explain what you want that to do?

I’m trying to implement node allocators, which could make use of undefined memory like arrays do.

You could use a Ref, e.g. Ref{Tuple{Int, Int}}() will be a mutable container that can be updated later.

Or you could use StaticArrays.jl’s MVector. e.g. MVector{2, Int}(undef).

Ref{Tuple{Int, Int}}() I understand, but if we have a vector of these there a probably some allocations required.

If you have a vector of them then you just use undef.

julia> v = Vector{Tuple{Int, Int}}(undef, 2)
2-element Vector{Tuple{Int64, Int64}}:
 (9, 4)
 (11, 5)
1 Like

Just noticed Create a struct with uninitialized fields - #5 by dfdx in the feed.