4 ms·
Since memory is copied, it's really not clear to me what the advantage is of using value_ptr over just using values. Is it just about heap vs. stack?
by radarsat1 9y ago
Since memory is copied, it's really not clear to me what the advantage is of using value_ptr over just using values.
Is it just about heap vs. stack?
- Eyas 9y agoI 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?
- deleted 9y ago[deleted]