| I must be misunderstanding something from this article. With: struct Node { std::vector<Connection> connections;
};struct Connection { Node* from, to;
};Does this mean that to create the vector of connections, Nodes are created, and references are taken to store in the Connections? And then the Nodes are stored in the list, with std::move()? I don't understand why you would want to go down that road. Intuitively, I would assume that you are not safe from an object copy somewhere down the line and your graph then comes crashing down like a house of cards. Wouldn't it make more sense to store the nodes as pointers? If you like to live dangerously, something like: struct Graph { std::vector<std::list<Node\*>> nodes;
};Or better: struct Graph { std::vector<std::list<std::unique_ptr<Node>>> nodes;
};The later will give you plenty of warnings if you do not copy Nodes around with std::move(). Or less performant, but maybe safer, std::shared_ptr<Node>, together with: struct Connection { std::weak_ptr<Node> from, to;
};so that you have some check guarantees before access? |