3 ms·
I don't think there's need for smart pointers at all, really. The "children" member could just be an unordered_map<T, Node>. Edit: on second thought, having a
by nemetroid 7y ago
I don't think there's need for smart pointers at all, really. The "children" member could just be an unordered_map<T, Node>.
Edit: on second thought, having a class contain a container of itself actually isn't allowed (though you would think it would be in cases like this).
Edit again: apparently it depends on the container. unordered_map does not allow instantiation with an incomplete type, but other containers do (e.g. vector or map).
- stabbles 7y agoYes, I was playing around with it as well. It seems the support has been out there for a while, but officially since C++17 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4371.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n437... was accepted, s.t. std::vector, std::list and std::forward_list can work with incomplete types: struct example { std::vector<example> xs; };
- saagarjha 7y agoI believe containers can contain incomplete types as of C++17, but you cannot use their members.