Why no "w != NULL" assertion before boost/intrusive/rbtree_algorithms.hpp:511 like before the line 476?

Boost version: latest release file: boost/intrusive/rbtree_algorithms.hpp function: rebalance_after_erasure_restore_invariants in this if-branch ``` if(x == x_parent_left){ //x is left child ``` there is "w != NULL" assertion before variable 'w' access: ``` BOOST_INTRUSIVE_INVARIANT_ASSERT(w); if(NodeTraits::get_color(w) == NodeTraits::red()){ ``` but in else-branch there is no same assertion before variable 'w' access: ``` if(NodeTraits::get_color(w) == NodeTraits::red()){ ``` Why? Are there no assertion in else-branch intentionally due to the rbtree structure itself? Thanks.

El 04/08/2025 a las 15:30, Andrew via Boost escribió:
Boost version: latest release
file: boost/intrusive/rbtree_algorithms.hpp
function: rebalance_after_erasure_restore_invariants
in this if-branch
``` if(x == x_parent_left){ //x is left child ```
there is "w != NULL" assertion before variable 'w' access:
``` BOOST_INTRUSIVE_INVARIANT_ASSERT(w); if(NodeTraits::get_color(w) == NodeTraits::red()){ ```
but in else-branch there is no same assertion before variable 'w' access:
``` if(NodeTraits::get_color(w) == NodeTraits::red()){ ```
Why? Are there no assertion in else-branch intentionally due to the rbtree structure itself?
The classic rbtree code was split in several steps (the common bstree part and after that, rbtree and avltree specific parts). The global algorithm guarantees that that those "w" nodes are never null. I guess that while refactoring all that code I didn't have any need to explicitly assert that invariant to catch my errors. I've just added that additional invariant check so that the code is now less confusing: https://github.com/boostorg/intrusive/commit/03bcd012fbc172304ad7460c36b1ef0... Ion
participants (2)
-
achinkoff@gmail.com
-
Ion Gaztañaga