I am working on multibody simulations. In my code's hierarchy, a (physical) System has several RigidBodys stored in a table std::map<std::string, RigidBody>. Each RigidBody instance similarly has a series of Nodes stored in a table. These Nodes can be flagged as special.
I would like the System to have a way to access the special nodes.
I could do this by, e.g., creating a std::vector of std::reference_wrappers to those Nodes. However, if the Node or its parent is destroyed, the reference is left dangling.
I could also define a function that iterates through every RigidBody and Node, but it seems rather inefficient, since the number of Nodes can be large.
What approach would not involve dangling pointers/references, but would also not require to iterate through every Node only to access the flagged instances?