Having a mutable struct, e.g.:
mutable struct Point x y end
is it possible to construct its instance with uninitialized fields and set them later? E.g.:
p = create_uninitialized(Point) # <-- anything like this? p.x = 10.0 p.y = 20.0
Note: we can do it with arrays, e.g.
Alternatively, I’d be happy to hear about
similar() for structs, i.e. a function that takes an instance of a struct and creates similar instance with dummy field values:
p = Point(8.0, 11.0) p2 = similar_struct(p) # <-- like this p2.x = 10.0 p2.y = 20.0
Currently I use:
p = Point(8.0, 10.0) p2 = deepcopy(p) p2.x = 10.0 p2.y = 20.0
deepcopy is expensive and doesn’t work for all types.