Hacker News new | ask | show | jobs
by cesarb 4046 days ago
> The primary technique is to embed the type that is iterated over in a larger struct which contains the links. This way I can give out references to the inner type without fear of invalidating the iterator.

I see. I was too fixated in embedding a small struct with the links within the larger struct (in the style of the Linux kernel "struct list_head"), and didn't think of doing the opposite.

It probably makes being in several intrusive structs at the same time much more complicated, but I think it's possible to do without breaking anything.