Thanks to visit codestin.com
Credit goes to github.com

Skip to content

<xtree> : Is this determine statement redundant? #1913

@Kamichanw

Description

@Kamichanw
template <class _Moveit>
_Nodeptr _Copy_nodes(_Nodeptr _Rootnode, _Nodeptr _Wherenode, _Moveit _Movefl) {
    // copy entire subtree, recursively
    const auto _Scary = _Get_scary();
    _Nodeptr _Newroot = _Scary->_Myhead; // point at nil node

    if (!_Rootnode->_Isnil) { // copy or move a node, then any subtrees
        bool_constant<is_same_v<key_type, value_type>> _Is_set;
        _Nodeptr _Pnode = _Copy_or_move(_Rootnode->_Myval, _Movefl, _Is_set);
        _Pnode->_Parent = _Wherenode;
        _Pnode->_Color  = _Rootnode->_Color;
        if (_Newroot->_Isnil) {
            _Newroot = _Pnode; // memorize new root
        }

        _TRY_BEGIN
        _Pnode->_Left  = _Copy_nodes(_Rootnode->_Left, _Pnode, _Movefl);
        _Pnode->_Right = _Copy_nodes(_Rootnode->_Right, _Pnode, _Movefl);
        _CATCH_ALL
        _Scary->_Erase_tree_and_orphan(_Getal(), _Newroot); // subtree copy failed, bail out
        _RERAISE;
        _CATCH_END
    }

    return _Newroot; // return newly constructed tree
}

In function _Copy_nodes which is applied to copy a tree, _Newroot->_Isnil is always true, but here:

if (_Newroot->_Isnil) {
            _Newroot = _Pnode; // memorize new root
}

why still determine if it is nil?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething can be improvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions