I have a:
template<class K,class V> struct Node { node_ptr parent_;//node_ptr is a shared_ptr<Node<K,V>> node_ptr& get_parent()const { return parent_; } void set_parent(node_ptr& p) { parent_ = p; } //the get set for left and right are analogical }; I cannot understand why this works:
auto zz = get_parent(get_parent(z)); rb_left_rotate(t,zz); but this does not:
rb_left_rotate(t,get_parent(get_parent(z))); by works I mean that inside rb_left_rotate I have:
template<class Tree_T, class Node_T> void rb_left_rotate(Tree_T& t,Node_T& x) { auto y = get_right(x); set_right(x,get_left(y)); if (get_left(y)) { set_parent(get_left(y),x); } auto tmp = get_parent(x); //y's current parrent is x set_parent(y,tmp);//by works I mean that this line WILL NOT set x to empty ...... }
get_parentthat returns a reference to a shared pointer but you are then asking about a different code that uses a free function from which you do not state what is returned (my guess: the free function returns by value)