Why does recursion appear in QVector?
-
In this code, recursion appears in QVector, but not in std::vector.
struct TreeNode { QString name; QVector<TreeNode> nodes; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); TreeNode n0{ "n0" }; n0.nodes.push_back(n0); n0.nodes[0].nodes.push_back(n0); }
&n0 0x0000002fa1bcf6e8 {name=n0 nodes={ size = 1 } }
&n0.nodes[0] 0x0000013ce627d2f8 {name=n0 nodes={ size = 1 } }
&n0.nodes[0].nodes[0] 0x0000013ce627e878 {name=n0 nodes={ size = 1 } }
&n0.nodes[0].nodes[0].nodes[0] 0x0000013ce627d2f8 {name=n0 nodes={ size = 1 } }
&n0.nodes[0].nodes[0].nodes[0].nodes[0] 0x0000013ce627e878 {name=n0 nodes={ size = 1 } } -
That's surprising, both should show recursive behaviour. Because you modify the nodes wich would trigger a copy of the vector element.
~
Actually std::vector has no implizit sharing, it does the copy directly. Probably the reason why you see different behaviour. -
That's surprising, both should show recursive behaviour. Because you modify the nodes wich would trigger a copy of the vector element.
~
Actually std::vector has no implizit sharing, it does the copy directly. Probably the reason why you see different behaviour. -