4 ms·
I think its about recursive types/members, e.g. class Tree { Tree _left, _right; }; Won't compile because it has an infinite size. However class Tree
by Eyas 9y ago
I think its about recursive types/members, e.g.
class Tree { Tree _left, _right; };
Won't compile because it has an infinite size. However
class Tree { Tree *_left, *_right; };
Compiles, but the author contends that a more explicit description of the ownership semantics is better:
class Tree { value_ptr<Tree> _left, _right; }
This is also why `value_ptr` is different than `optional`.
- waqf 9y agoI think you have to say something about the copy semantics too, because if you ignore those, value_ptr would be synonymous with unique_ptr. class Tree { Tree *_left, *_right; }; Tree y = x; makes a shallow copy. class Tree { unique_ptr<Tree> _left, _right; }; Tree y = x; doesn't compile, but class Tree { value_ptr<Tree> _left, _right; }; Tree y = x; makes a deep copy.
- waynecochran 9y agoWith value-ptr's would traversing the tree require making copies of examined nodes as you search? What would the tree_search method look like?