[llvm-branch-commits] [libcxx] [libc++] Add accessor functions to __tree_node_base (PR #147679)

Nikolas Klauser via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jul 9 05:30:06 PDT 2025


https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/147679

>From 36de75b6af9ab6bcfeb94f794d3ec5537ad7d168 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 9 Jun 2025 18:17:31 +0200
Subject: [PATCH] [libc++] Add accessor functions to __tree_node_base

---
 libcxx/include/__tree                         | 230 ++++----
 .../tree_balance_after_insert.pass.cpp        | 513 +++++++++---------
 .../associative/tree_left_rotate.pass.cpp     |   1 +
 .../associative/tree_remove.pass.cpp          | 488 ++++++++---------
 .../associative/tree_right_rotate.pass.cpp    |   1 +
 5 files changed, 630 insertions(+), 603 deletions(-)

diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 9d4ba3ad0639c..6b025bcf3496d 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -77,6 +77,11 @@ class __map_iterator;
 template <class _TreeIterator>
 class __map_const_iterator;
 
+enum class __tree_color : bool {
+  __red = false,
+  __black = true,
+};
+
 /*
 
 _NodePtr algorithms
@@ -102,7 +107,7 @@ __root, have a non-null __parent_ field.
 // Precondition:  __x != nullptr.
 template <class _NodePtr>
 inline _LIBCPP_HIDE_FROM_ABI bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT {
-  return __x == __x->__parent_->__left_;
+  return __x == __x->__get_parent()->__left_;
 }
 
 // Determines if the subtree rooted at __x is a proper red black subtree.  If
@@ -110,6 +115,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT {
 //    __x is an improper subtree, returns 0.
 template <class _NodePtr>
 unsigned __tree_sub_invariant(_NodePtr __x) {
+  using enum __tree_color;
+
   if (__x == nullptr)
     return 1;
   // parent consistency checked by caller
@@ -123,10 +130,10 @@ unsigned __tree_sub_invariant(_NodePtr __x) {
   if (__x->__left_ == __x->__right_ && __x->__left_ != nullptr)
     return 0;
   // If this is red, neither child can be red
-  if (!__x->__is_black_) {
-    if (__x->__left_ && !__x->__left_->__is_black_)
+  if (__x->__color_ == __red) {
+    if (__x->__left_ && __x->__left_->__color_ == __red)
       return 0;
-    if (__x->__right_ && !__x->__right_->__is_black_)
+    if (__x->__right_ && __x->__right_->__color_ == __red)
       return 0;
   }
   unsigned __h = std::__tree_sub_invariant(__x->__left_);
@@ -134,7 +141,7 @@ unsigned __tree_sub_invariant(_NodePtr __x) {
     return 0; // invalid left subtree
   if (__h != std::__tree_sub_invariant(__x->__right_))
     return 0;                    // invalid or different height right subtree
-  return __h + __x->__is_black_; // return black height of this node
+  return __h + (__x->__color_ == __black ? 1 : 0); // return black height of this node
 }
 
 // Determines if the red black tree rooted at __root is a proper red black tree.
@@ -150,7 +157,7 @@ _LIBCPP_HIDE_FROM_ABI bool __tree_invariant(_NodePtr __root) {
   if (!std::__tree_is_left_child(__root))
     return false;
   // root must be black
-  if (!__root->__is_black_)
+  if (__root->__color_ == __tree_color::__red)
     return false;
   // do normal node checks
   return std::__tree_sub_invariant(__root) != 0;
@@ -192,7 +199,7 @@ inline _LIBCPP_HIDE_FROM_ABI _EndNodePtr __tree_next_iter(_NodePtr __x) _NOEXCEP
     return static_cast<_EndNodePtr>(std::__tree_min(__x->__right_));
   while (!std::__tree_is_left_child(__x))
     __x = __x->__parent_unsafe();
-  return static_cast<_EndNodePtr>(__x->__parent_);
+  return static_cast<_EndNodePtr>(__x->__get_parent());
 }
 
 // Returns:  pointer to the previous in-order node before __x.
@@ -236,9 +243,9 @@ _LIBCPP_HIDE_FROM_ABI void __tree_left_rotate(_NodePtr __x) _NOEXCEPT {
   __x->__right_ = __y->__left_;
   if (__x->__right_ != nullptr)
     __x->__right_->__set_parent(__x);
-  __y->__parent_ = __x->__parent_;
+  __y->__set_parent(__x->__get_parent());
   if (std::__tree_is_left_child(__x))
-    __x->__parent_->__left_ = __y;
+    __x->__get_parent()->__left_ = __y;
   else
     __x->__parent_unsafe()->__right_ = __y;
   __y->__left_ = __x;
@@ -255,9 +262,9 @@ _LIBCPP_HIDE_FROM_ABI void __tree_right_rotate(_NodePtr __x) _NOEXCEPT {
   __x->__left_ = __y->__right_;
   if (__x->__left_ != nullptr)
     __x->__left_->__set_parent(__x);
-  __y->__parent_ = __x->__parent_;
+  __y->__set_parent(__x->__get_parent());
   if (std::__tree_is_left_child(__x))
-    __x->__parent_->__left_ = __y;
+    __x->__get_parent()->__left_ = __y;
   else
     __x->__parent_unsafe()->__right_ = __y;
   __y->__right_ = __x;
@@ -275,46 +282,47 @@ template <class _NodePtr>
 _LIBCPP_HIDE_FROM_ABI void __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT {
   _LIBCPP_ASSERT_INTERNAL(__root != nullptr, "Root of the tree shouldn't be null");
   _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Can't attach null node to a leaf");
-  __x->__is_black_ = __x == __root;
-  while (__x != __root && !__x->__parent_unsafe()->__is_black_) {
-    // __x->__parent_ != __root because __x->__parent_->__is_black == false
+  using enum __tree_color;
+  __x->__set_color(__x == __root ? __black : __red);
+  while (__x != __root && __x->__parent_unsafe()->__get_color() == __red) {
+    // __x->__parent_ != __root because __x->__parent_->__get_color() == __red
     if (std::__tree_is_left_child(__x->__parent_unsafe())) {
       _NodePtr __y = __x->__parent_unsafe()->__parent_unsafe()->__right_;
-      if (__y != nullptr && !__y->__is_black_) {
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = true;
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = __x == __root;
-        __y->__is_black_ = true;
+      if (__y != nullptr && __y->__get_color() == __red) {
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__black);
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__x == __root ? __black : __red);
+        __y->__set_color(__black);
       } else {
         if (!std::__tree_is_left_child(__x)) {
           __x = __x->__parent_unsafe();
           std::__tree_left_rotate(__x);
         }
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = true;
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = false;
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__black);
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__red);
         std::__tree_right_rotate(__x);
         break;
       }
     } else {
-      _NodePtr __y = __x->__parent_unsafe()->__parent_->__left_;
-      if (__y != nullptr && !__y->__is_black_) {
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = true;
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = __x == __root;
-        __y->__is_black_ = true;
+      _NodePtr __y = __x->__parent_unsafe()->__get_parent()->__left_;
+      if (__y != nullptr && __y->__get_color() == __red) {
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__black);
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__x == __root ? __black : __red);
+        __y->__set_color(__black);
       } else {
         if (std::__tree_is_left_child(__x)) {
           __x = __x->__parent_unsafe();
           std::__tree_right_rotate(__x);
         }
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = true;
-        __x              = __x->__parent_unsafe();
-        __x->__is_black_ = false;
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__black);
+        __x = __x->__parent_unsafe();
+        __x->__set_color(__red);
         std::__tree_left_rotate(__x);
         break;
       }
@@ -332,6 +340,9 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
   _LIBCPP_ASSERT_INTERNAL(__root != nullptr, "Root node should not be null");
   _LIBCPP_ASSERT_INTERNAL(__z != nullptr, "The node to remove should not be null");
   _LIBCPP_ASSERT_INTERNAL(std::__tree_invariant(__root), "The tree invariants should hold");
+
+  using enum __tree_color;
+
   // __z will be removed from the tree.  Client still needs to destruct/deallocate it
   // __y is either __z, or if __z has two children, __tree_next(__z).
   // __y will have at most one child.
@@ -343,9 +354,9 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
   _NodePtr __w = nullptr;
   // link __x to __y's parent, and find __w
   if (__x != nullptr)
-    __x->__parent_ = __y->__parent_;
+    __x->__set_parent(__y->__get_parent());
   if (std::__tree_is_left_child(__y)) {
-    __y->__parent_->__left_ = __x;
+    __y->__get_parent()->__left_ = __x;
     if (__y != __root)
       __w = __y->__parent_unsafe()->__right_;
     else
@@ -353,16 +364,16 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
   } else {
     __y->__parent_unsafe()->__right_ = __x;
     // __y can't be root if it is a right child
-    __w = __y->__parent_->__left_;
+    __w = __y->__get_parent()->__left_;
   }
-  bool __removed_black = __y->__is_black_;
+  bool __removed_black = __y->__get_color() == __black;
   // If we didn't remove __z, do so now by splicing in __y for __z,
   //    but copy __z's color.  This does not impact __x or __w.
   if (__y != __z) {
     // __z->__left_ != nulptr but __z->__right_ might == __x == nullptr
-    __y->__parent_ = __z->__parent_;
+    __y->__set_parent(__z->__get_parent());
     if (std::__tree_is_left_child(__z))
-      __y->__parent_->__left_ = __y;
+      __y->__get_parent()->__left_ = __y;
     else
       __y->__parent_unsafe()->__right_ = __y;
     __y->__left_ = __z->__left_;
@@ -370,7 +381,7 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
     __y->__right_ = __z->__right_;
     if (__y->__right_ != nullptr)
       __y->__right_->__set_parent(__y);
-    __y->__is_black_ = __z->__is_black_;
+    __y->__set_color(__z->__get_color());
     if (__root == __z)
       __root = __y;
   }
@@ -390,7 +401,7 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
     //   different black heights under left and right pointers.
     // if (__x == __root || __x != nullptr && !__x->__is_black_)
     if (__x != nullptr)
-      __x->__is_black_ = true;
+      __x->__set_color(__black);
     else {
       //  Else __x isn't root, and is "doubly black", even though it may
       //     be null.  __w can not be null here, else the parent would
@@ -400,9 +411,9 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
       while (true) {
         if (!std::__tree_is_left_child(__w)) // if x is left child
         {
-          if (!__w->__is_black_) {
-            __w->__is_black_                    = true;
-            __w->__parent_unsafe()->__is_black_ = false;
+          if (__w->__get_color() == __red) {
+            __w->__set_color(__black);
+            __w->__parent_unsafe()->__set_color(__red);
             std::__tree_left_rotate(__w->__parent_unsafe());
             // __x is still valid
             // reset __root only if necessary
@@ -412,40 +423,40 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
             __w = __w->__left_->__right_;
           }
           // __w->__is_black_ is now true, __w may have null children
-          if ((__w->__left_ == nullptr || __w->__left_->__is_black_) &&
-              (__w->__right_ == nullptr || __w->__right_->__is_black_)) {
-            __w->__is_black_ = false;
-            __x              = __w->__parent_unsafe();
+          if ((__w->__left_ == nullptr || __w->__left_->__get_color() == __black) &&
+              (__w->__right_ == nullptr || __w->__right_->__get_color() == __black)) {
+            __w->__set_color(__red);
+            __x = __w->__parent_unsafe();
             // __x can no longer be null
-            if (__x == __root || !__x->__is_black_) {
-              __x->__is_black_ = true;
+            if (__x == __root || __x->__get_color() == __red) {
+              __x->__set_color(__black);
               break;
             }
             // reset sibling, and it still can't be null
-            __w = std::__tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__parent_->__left_;
+            __w = std::__tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__get_parent()->__left_;
             // continue;
           } else // __w has a red child
           {
-            if (__w->__right_ == nullptr || __w->__right_->__is_black_) {
+            if (__w->__right_ == nullptr || __w->__right_->__get_color() == __black) {
               // __w left child is non-null and red
-              __w->__left_->__is_black_ = true;
-              __w->__is_black_          = false;
+              __w->__left_->__set_color(__black);
+              __w->__set_color(__red);
               std::__tree_right_rotate(__w);
               // __w is known not to be root, so root hasn't changed
               // reset sibling, and it still can't be null
               __w = __w->__parent_unsafe();
             }
             // __w has a right red child, left child may be null
-            __w->__is_black_                    = __w->__parent_unsafe()->__is_black_;
-            __w->__parent_unsafe()->__is_black_ = true;
-            __w->__right_->__is_black_          = true;
+            __w->__set_color(__w->__parent_unsafe()->__get_color());
+            __w->__parent_unsafe()->__set_color(__black);
+            __w->__right_->__set_color(__black);
             std::__tree_left_rotate(__w->__parent_unsafe());
             break;
           }
         } else {
-          if (!__w->__is_black_) {
-            __w->__is_black_                    = true;
-            __w->__parent_unsafe()->__is_black_ = false;
+          if (__w->__get_color() == __red) {
+            __w->__set_color(__black);
+            __w->__parent_unsafe()->__set_color(__red);
             std::__tree_right_rotate(__w->__parent_unsafe());
             // __x is still valid
             // reset __root only if necessary
@@ -455,33 +466,33 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEP
             __w = __w->__right_->__left_;
           }
           // __w->__is_black_ is now true, __w may have null children
-          if ((__w->__left_ == nullptr || __w->__left_->__is_black_) &&
-              (__w->__right_ == nullptr || __w->__right_->__is_black_)) {
-            __w->__is_black_ = false;
-            __x              = __w->__parent_unsafe();
+          if ((__w->__left_ == nullptr || __w->__left_->__get_color() == __black) &&
+              (__w->__right_ == nullptr || __w->__right_->__get_color() == __black)) {
+            __w->__set_color(__red);
+            __x = __w->__parent_unsafe();
             // __x can no longer be null
-            if (!__x->__is_black_ || __x == __root) {
-              __x->__is_black_ = true;
+            if (__x->__get_color() == __red || __x == __root) {
+              __x->__set_color(__black);
               break;
             }
             // reset sibling, and it still can't be null
-            __w = std::__tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__parent_->__left_;
+            __w = std::__tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__get_parent()->__left_;
             // continue;
           } else // __w has a red child
           {
-            if (__w->__left_ == nullptr || __w->__left_->__is_black_) {
+            if (__w->__left_ == nullptr || __w->__left_->__get_color() == __black) {
               // __w right child is non-null and red
-              __w->__right_->__is_black_ = true;
-              __w->__is_black_           = false;
+              __w->__right_->__set_color(__black);
+              __w->__set_color(__red);
               std::__tree_left_rotate(__w);
               // __w is known not to be root, so root hasn't changed
               // reset sibling, and it still can't be null
               __w = __w->__parent_unsafe();
             }
             // __w has a left red child, right child may be null
-            __w->__is_black_                    = __w->__parent_unsafe()->__is_black_;
-            __w->__parent_unsafe()->__is_black_ = true;
-            __w->__left_->__is_black_           = true;
+            __w->__set_color(__w->__parent_unsafe()->__get_color());
+            __w->__parent_unsafe()->__set_color(__black);
+            __w->__left_->__set_color(__black);
             std::__tree_right_rotate(__w->__parent_unsafe());
             break;
           }
@@ -563,12 +574,19 @@ public:
   using __end_node_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<_VoidPtr, __tree_end_node<pointer> >;
 
   pointer __right_;
+
+private:
   __end_node_pointer __parent_;
-  bool __is_black_;
+  __tree_color __color_;
 
+public:
   _LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const { return static_cast<pointer>(__parent_); }
 
   _LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__end_node_pointer>(__p); }
+  _LIBCPP_HIDE_FROM_ABI void __set_parent(__end_node_pointer __p) { __parent_ = __p; }
+  _LIBCPP_HIDE_FROM_ABI __end_node_pointer __get_parent() const { return __parent_; }
+  _LIBCPP_HIDE_FROM_ABI __tree_color __get_color() const { return __color_; }
+  _LIBCPP_HIDE_FROM_ABI void __set_color(__tree_color __color) { __color_ = __color; }
 
   ~__tree_node_base()                                  = delete;
   __tree_node_base(__tree_node_base const&)            = delete;
@@ -1254,8 +1272,8 @@ private:
     _LIBCPP_HIDE_FROM_ABI ~_DetachedTreeCache() {
       __t_->destroy(__cache_elem_);
       if (__cache_root_) {
-        while (__cache_root_->__parent_ != nullptr)
-          __cache_root_ = static_cast<__node_pointer>(__cache_root_->__parent_);
+        while (__cache_root_->__get_parent() != nullptr)
+          __cache_root_ = static_cast<__node_pointer>(__cache_root_->__get_parent());
         __t_->destroy(__cache_root_);
       }
     }
@@ -1296,11 +1314,11 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const all
 template <class _Tp, class _Compare, class _Allocator>
 typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
 __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_from_tree(__tree* __t) _NOEXCEPT {
-  __node_pointer __cache                = static_cast<__node_pointer>(__t->__begin_node());
-  __t->__begin_node()                   = __t->__end_node();
-  __t->__end_node()->__left_->__parent_ = nullptr;
-  __t->__end_node()->__left_            = nullptr;
-  __t->size()                           = 0;
+  __node_pointer __cache = static_cast<__node_pointer>(__t->__begin_node());
+  __t->__begin_node()    = __t->__end_node();
+  __t->__end_node()->__left_->__set_parent(__parent_pointer(nullptr));
+  __t->__end_node()->__left_ = nullptr;
+  __t->size()                = 0;
   // __cache->__left_ == nullptr
   if (__cache->__right_ != nullptr)
     __cache = static_cast<__node_pointer>(__cache->__right_);
@@ -1316,18 +1334,18 @@ __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_from_tree(__tree
 template <class _Tp, class _Compare, class _Allocator>
 typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
 __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_pointer __cache) _NOEXCEPT {
-  if (__cache->__parent_ == nullptr)
+  if (__cache->__get_parent() == nullptr)
     return nullptr;
   if (std::__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) {
-    __cache->__parent_->__left_ = nullptr;
-    __cache                     = static_cast<__node_pointer>(__cache->__parent_);
+    __cache->__get_parent()->__left_ = nullptr;
+    __cache                     = static_cast<__node_pointer>(__cache->__get_parent());
     if (__cache->__right_ == nullptr)
       return __cache;
     return static_cast<__node_pointer>(std::__tree_leaf(__cache->__right_));
   }
   // __cache is right child
   __cache->__parent_unsafe()->__right_ = nullptr;
-  __cache                              = static_cast<__node_pointer>(__cache->__parent_);
+  __cache                              = static_cast<__node_pointer>(__cache->__get_parent());
   if (__cache->__left_ == nullptr)
     return __cache;
   return static_cast<__node_pointer>(std::__tree_leaf(__cache->__left_));
@@ -1403,10 +1421,10 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
   if (size() == 0)
     __begin_node() = __end_node();
   else {
-    __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
-    __t.__begin_node()               = __t.__end_node();
-    __t.__end_node()->__left_        = nullptr;
-    __t.size()                       = 0;
+    __end_node()->__left_->__set_parent(static_cast<__end_node_pointer>(__end_node()));
+    __t.__begin_node()        = __t.__end_node();
+    __t.__end_node()->__left_ = nullptr;
+    __t.size()                = 0;
   }
 }
 
@@ -1417,13 +1435,13 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __
     if (__t.size() == 0)
       __begin_node() = __end_node();
     else {
-      __begin_node()                   = __t.__begin_node();
-      __end_node()->__left_            = __t.__end_node()->__left_;
-      __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
-      size()                           = __t.size();
-      __t.__begin_node()               = __t.__end_node();
-      __t.__end_node()->__left_        = nullptr;
-      __t.size()                       = 0;
+      __begin_node()        = __t.__begin_node();
+      __end_node()->__left_ = __t.__end_node()->__left_;
+      __end_node()->__left_->__set_parent(static_cast<__end_node_pointer>(__end_node()));
+      size()                    = __t.size();
+      __t.__begin_node()        = __t.__end_node();
+      __t.__end_node()->__left_ = nullptr;
+      __t.size()                = 0;
     }
   } else {
     __begin_node() = __end_node();
@@ -1442,10 +1460,10 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type)
   if (size() == 0)
     __begin_node() = __end_node();
   else {
-    __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
-    __t.__begin_node()               = __t.__end_node();
-    __t.__end_node()->__left_        = nullptr;
-    __t.size()                       = 0;
+    __end_node()->__left_->__set_parent(static_cast<__end_node_pointer>(__end_node()));
+    __t.__begin_node()        = __t.__end_node();
+    __t.__end_node()->__left_ = nullptr;
+    __t.size()                = 0;
   }
 }
 
@@ -1515,11 +1533,11 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
   if (size() == 0)
     __begin_node() = __end_node();
   else
-    __end_node()->__left_->__parent_ = __end_node();
+    __end_node()->__left_->__set_parent(static_cast<__end_node_pointer>(__end_node()));
   if (__t.size() == 0)
     __t.__begin_node() = __t.__end_node();
   else
-    __t.__end_node()->__left_->__parent_ = __t.__end_node();
+    __t.__end_node()->__left_->__set_parent(static_cast<__end_node_pointer>(__t.__end_node()));
 }
 
 template <class _Tp, class _Compare, class _Allocator>
@@ -1713,7 +1731,7 @@ void __tree<_Tp, _Compare, _Allocator>::__insert_node_at(
     __end_node_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT {
   __new_node->__left_   = nullptr;
   __new_node->__right_  = nullptr;
-  __new_node->__parent_ = __parent;
+  __new_node->__set_parent(__parent);
   // __new_node->__is_black_ is initialized in __tree_balance_after_insert
   __child = __new_node;
   if (__begin_node()->__left_ != nullptr)
@@ -2233,7 +2251,7 @@ __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT {
     if (__np->__right_ != nullptr)
       __begin_node() = static_cast<__end_node_pointer>(__np->__right_);
     else
-      __begin_node() = static_cast<__end_node_pointer>(__np->__parent_);
+      __begin_node() = static_cast<__end_node_pointer>(__np->__get_parent());
   }
   --size();
   std::__tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__np));
diff --git a/libcxx/test/libcxx/containers/associative/tree_balance_after_insert.pass.cpp b/libcxx/test/libcxx/containers/associative/tree_balance_after_insert.pass.cpp
index ccd84af44c3a5..27fcef3f1360a 100644
--- a/libcxx/test/libcxx/containers/associative/tree_balance_after_insert.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/tree_balance_after_insert.pass.cpp
@@ -8,7 +8,7 @@
 
 // Not a portable test
 
-// Precondition:  __root->__is_black_ == true
+// Precondition:  __root->__color_ == std::__tree_color::__black
 // template <class _NodePtr>
 // void
 // __tree_balance_after_insert(_NodePtr __root, _NodePtr __x)
@@ -24,12 +24,15 @@ struct Node {
   Node* __left_;
   Node* __right_;
   Node* __parent_;
-  bool __is_black_;
+  std::__tree_color __color_;
 
   Node* __parent_unsafe() const { return __parent_; }
   void __set_parent(Node* x) { __parent_ = x; }
+  Node* __get_parent() { return __parent_; }
+  void __set_color(std::__tree_color __color) { __color_ = __color; }
+  std::__tree_color __get_color() { return __color_; }
 
-  Node() : __left_(), __right_(), __parent_(), __is_black_() {}
+  Node() : __left_(), __right_(), __parent_(), __color_() {}
 };
 
 void test1() {
@@ -45,22 +48,22 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = &a;
     b.__right_    = 0;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = 0;
     d.__right_    = 0;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -71,22 +74,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == &a);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == 0);
     assert(d.__right_ == 0);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -100,22 +103,22 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = 0;
     b.__right_    = &a;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = 0;
     d.__right_    = 0;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -126,22 +129,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == 0);
     assert(b.__right_ == &a);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == 0);
     assert(d.__right_ == 0);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -155,22 +158,22 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = 0;
     b.__right_    = 0;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = &a;
     d.__right_    = 0;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &d;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -181,22 +184,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == 0);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == &a);
     assert(d.__right_ == 0);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &d);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -210,22 +213,22 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = 0;
     b.__right_    = 0;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = 0;
     d.__right_    = &a;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &d;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -236,22 +239,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == 0);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == 0);
     assert(d.__right_ == &a);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &d);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -270,37 +273,37 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = &a;
     b.__right_    = &g;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = &h;
     d.__right_    = &i;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &b;
     a.__left_     = &e;
     a.__right_    = &f;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     e.__parent_   = &a;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &a;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &b;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     h.__parent_   = &d;
-    h.__is_black_ = true;
+    h.__color_ = std::__tree_color::__black;
 
     i.__parent_   = &d;
-    i.__is_black_ = true;
+    i.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -311,22 +314,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == &a);
     assert(b.__right_ == &g);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == &h);
     assert(d.__right_ == &i);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == &e);
     assert(a.__right_ == &f);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -345,37 +348,37 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = &g;
     b.__right_    = &a;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = &h;
     d.__right_    = &i;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &b;
     a.__left_     = &e;
     a.__right_    = &f;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     e.__parent_   = &a;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &a;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &b;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     h.__parent_   = &d;
-    h.__is_black_ = true;
+    h.__color_ = std::__tree_color::__black;
 
     i.__parent_   = &d;
-    i.__is_black_ = true;
+    i.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -386,22 +389,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == &g);
     assert(b.__right_ == &a);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == &h);
     assert(d.__right_ == &i);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == &e);
     assert(a.__right_ == &f);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -420,37 +423,37 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = &g;
     b.__right_    = &h;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = &a;
     d.__right_    = &i;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &d;
     a.__left_     = &e;
     a.__right_    = &f;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     e.__parent_   = &a;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &a;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &b;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     h.__parent_   = &b;
-    h.__is_black_ = true;
+    h.__color_ = std::__tree_color::__black;
 
     i.__parent_   = &d;
-    i.__is_black_ = true;
+    i.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -461,22 +464,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == &g);
     assert(b.__right_ == &h);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == &a);
     assert(d.__right_ == &i);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &d);
     assert(a.__left_ == &e);
     assert(a.__right_ == &f);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -495,37 +498,37 @@ void test1() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &d;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = &g;
     b.__right_    = &h;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &c;
     d.__left_     = &i;
     d.__right_    = &a;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &d;
     a.__left_     = &e;
     a.__right_    = &f;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     e.__parent_   = &a;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &a;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &b;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     h.__parent_   = &b;
-    h.__is_black_ = true;
+    h.__color_ = std::__tree_color::__black;
 
     i.__parent_   = &d;
-    i.__is_black_ = true;
+    i.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -536,22 +539,22 @@ void test1() {
     assert(c.__parent_ == &root);
     assert(c.__left_ == &b);
     assert(c.__right_ == &d);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &c);
     assert(b.__left_ == &g);
     assert(b.__right_ == &h);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &c);
     assert(d.__left_ == &i);
     assert(d.__right_ == &a);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(a.__parent_ == &d);
     assert(a.__left_ == &e);
     assert(a.__right_ == &f);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
   }
 }
 
@@ -567,17 +570,17 @@ void test2() {
     c.__parent_   = &root;
     c.__left_     = &a;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &c;
     a.__left_     = 0;
     a.__right_    = &b;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     b.__parent_   = &a;
     b.__left_     = 0;
     b.__right_    = 0;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &b);
 
@@ -588,17 +591,17 @@ void test2() {
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
   }
   {
     Node root;
@@ -611,17 +614,17 @@ void test2() {
     a.__parent_   = &root;
     a.__left_     = 0;
     a.__right_    = &c;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &a;
     c.__left_     = &b;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     b.__parent_   = &c;
     b.__left_     = 0;
     b.__right_    = 0;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &b);
 
@@ -632,17 +635,17 @@ void test2() {
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
   }
   {
     Node root;
@@ -659,29 +662,29 @@ void test2() {
     c.__parent_   = &root;
     c.__left_     = &a;
     c.__right_    = &g;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &c;
     a.__left_     = &d;
     a.__right_    = &b;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     b.__parent_   = &a;
     b.__left_     = &e;
     b.__right_    = &f;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &a;
-    d.__is_black_ = true;
+    d.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &b;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &b;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &c;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &b);
 
@@ -692,29 +695,29 @@ void test2() {
     assert(c.__parent_ == &b);
     assert(c.__left_ == &f);
     assert(c.__right_ == &g);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == &d);
     assert(a.__right_ == &e);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &a);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(e.__parent_ == &a);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
 
     assert(f.__parent_ == &c);
-    assert(f.__is_black_ == true);
+    assert(f.__color_ == std::__tree_color::__black);
 
     assert(g.__parent_ == &c);
-    assert(g.__is_black_ == true);
+    assert(g.__color_ == std::__tree_color::__black);
   }
   {
     Node root;
@@ -731,29 +734,29 @@ void test2() {
     a.__parent_   = &root;
     a.__left_     = &d;
     a.__right_    = &c;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &a;
     c.__left_     = &b;
     c.__right_    = &g;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     b.__parent_   = &c;
     b.__left_     = &e;
     b.__right_    = &f;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &a;
-    d.__is_black_ = true;
+    d.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &b;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &b;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &c;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &b);
 
@@ -764,29 +767,29 @@ void test2() {
     assert(c.__parent_ == &b);
     assert(c.__left_ == &f);
     assert(c.__right_ == &g);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == &d);
     assert(a.__right_ == &e);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &a);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(e.__parent_ == &a);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
 
     assert(f.__parent_ == &c);
-    assert(f.__is_black_ == true);
+    assert(f.__color_ == std::__tree_color::__black);
 
     assert(g.__parent_ == &c);
-    assert(g.__is_black_ == true);
+    assert(g.__color_ == std::__tree_color::__black);
   }
 }
 
@@ -802,17 +805,17 @@ void test3() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = &a;
     b.__right_    = 0;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -823,17 +826,17 @@ void test3() {
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
   }
   {
     Node root;
@@ -846,17 +849,17 @@ void test3() {
     a.__parent_   = &root;
     a.__left_     = 0;
     a.__right_    = &b;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &a;
     b.__left_     = 0;
     b.__right_    = &c;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     std::__tree_balance_after_insert(root.__left_, &c);
 
@@ -867,17 +870,17 @@ void test3() {
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
   }
   {
     Node root;
@@ -894,29 +897,29 @@ void test3() {
     c.__parent_   = &root;
     c.__left_     = &b;
     c.__right_    = &g;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &c;
     b.__left_     = &a;
     b.__right_    = &f;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     a.__parent_   = &b;
     a.__left_     = &d;
     a.__right_    = &e;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &a;
-    d.__is_black_ = true;
+    d.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &a;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &b;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &c;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &a);
 
@@ -927,29 +930,29 @@ void test3() {
     assert(c.__parent_ == &b);
     assert(c.__left_ == &f);
     assert(c.__right_ == &g);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == &d);
     assert(a.__right_ == &e);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &a);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(e.__parent_ == &a);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
 
     assert(f.__parent_ == &c);
-    assert(f.__is_black_ == true);
+    assert(f.__color_ == std::__tree_color::__black);
 
     assert(g.__parent_ == &c);
-    assert(g.__is_black_ == true);
+    assert(g.__color_ == std::__tree_color::__black);
   }
   {
     Node root;
@@ -966,29 +969,29 @@ void test3() {
     a.__parent_   = &root;
     a.__left_     = &d;
     a.__right_    = &b;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     b.__parent_   = &a;
     b.__left_     = &e;
     b.__right_    = &c;
-    b.__is_black_ = false;
+    b.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = &f;
     c.__right_    = &g;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     d.__parent_   = &a;
-    d.__is_black_ = true;
+    d.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &b;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &c;
-    f.__is_black_ = true;
+    f.__color_ = std::__tree_color::__black;
 
     g.__parent_   = &c;
-    g.__is_black_ = true;
+    g.__color_ = std::__tree_color::__black;
 
     std::__tree_balance_after_insert(root.__left_, &c);
 
@@ -999,29 +1002,29 @@ void test3() {
     assert(c.__parent_ == &b);
     assert(c.__left_ == &f);
     assert(c.__right_ == &g);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == &d);
     assert(a.__right_ == &e);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(d.__parent_ == &a);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(e.__parent_ == &a);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
 
     assert(f.__parent_ == &c);
-    assert(f.__is_black_ == true);
+    assert(f.__color_ == std::__tree_color::__black);
 
     assert(g.__parent_ == &c);
-    assert(g.__is_black_ == true);
+    assert(g.__color_ == std::__tree_color::__black);
   }
 }
 
@@ -1046,12 +1049,12 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &a);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(a.__parent_ == &root);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   a.__right_  = &b;
   b.__parent_ = &a;
@@ -1063,17 +1066,17 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &a);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(a.__parent_ == &root);
   assert(a.__left_ == 0);
   assert(a.__right_ == &b);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &a);
   assert(b.__left_ == 0);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == false);
+  assert(b.__color_ == std::__tree_color::__red);
 
   b.__right_  = &c;
   c.__parent_ = &b;
@@ -1085,22 +1088,22 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &b);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == false);
+  assert(a.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &root);
   assert(b.__left_ == &a);
   assert(b.__right_ == &c);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &b);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == false);
+  assert(c.__color_ == std::__tree_color::__red);
 
   c.__right_  = &d;
   d.__parent_ = &c;
@@ -1112,27 +1115,27 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &b);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &root);
   assert(b.__left_ == &a);
   assert(b.__right_ == &c);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &b);
   assert(c.__left_ == 0);
   assert(c.__right_ == &d);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(d.__parent_ == &c);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == false);
+  assert(d.__color_ == std::__tree_color::__red);
 
   d.__right_  = &e;
   e.__parent_ = &d;
@@ -1144,32 +1147,32 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &b);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &root);
   assert(b.__left_ == &a);
   assert(b.__right_ == &d);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   assert(d.__parent_ == &b);
   assert(d.__left_ == &c);
   assert(d.__right_ == &e);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &d);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == false);
+  assert(c.__color_ == std::__tree_color::__red);
 
   assert(e.__parent_ == &d);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == false);
+  assert(e.__color_ == std::__tree_color::__red);
 
   e.__right_  = &f;
   f.__parent_ = &e;
@@ -1181,37 +1184,37 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &b);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &root);
   assert(b.__left_ == &a);
   assert(b.__right_ == &d);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   assert(d.__parent_ == &b);
   assert(d.__left_ == &c);
   assert(d.__right_ == &e);
-  assert(d.__is_black_ == false);
+  assert(d.__color_ == std::__tree_color::__red);
 
   assert(c.__parent_ == &d);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &d);
   assert(e.__left_ == 0);
   assert(e.__right_ == &f);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &e);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == false);
+  assert(f.__color_ == std::__tree_color::__red);
 
   f.__right_  = &g;
   g.__parent_ = &f;
@@ -1223,42 +1226,42 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &b);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &root);
   assert(b.__left_ == &a);
   assert(b.__right_ == &d);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   assert(d.__parent_ == &b);
   assert(d.__left_ == &c);
   assert(d.__right_ == &f);
-  assert(d.__is_black_ == false);
+  assert(d.__color_ == std::__tree_color::__red);
 
   assert(c.__parent_ == &d);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &d);
   assert(f.__left_ == &e);
   assert(f.__right_ == &g);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &f);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == false);
+  assert(e.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &f);
   assert(g.__left_ == 0);
   assert(g.__right_ == 0);
-  assert(g.__is_black_ == false);
+  assert(g.__color_ == std::__tree_color::__red);
 
   g.__right_  = &h;
   h.__parent_ = &g;
@@ -1270,47 +1273,47 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &d);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &root);
   assert(d.__left_ == &b);
   assert(d.__right_ == &f);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &d);
   assert(b.__left_ == &a);
   assert(b.__right_ == &c);
-  assert(b.__is_black_ == false);
+  assert(b.__color_ == std::__tree_color::__red);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &b);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &d);
   assert(f.__left_ == &e);
   assert(f.__right_ == &g);
-  assert(f.__is_black_ == false);
+  assert(f.__color_ == std::__tree_color::__red);
 
   assert(e.__parent_ == &f);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(g.__parent_ == &f);
   assert(g.__left_ == 0);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == false);
+  assert(h.__color_ == std::__tree_color::__red);
 }
 
 void test5() {
@@ -1334,12 +1337,12 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &h);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(h.__parent_ == &root);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   h.__left_   = &g;
   g.__parent_ = &h;
@@ -1351,17 +1354,17 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &h);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(h.__parent_ == &root);
   assert(h.__left_ == &g);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   assert(g.__parent_ == &h);
   assert(g.__left_ == 0);
   assert(g.__right_ == 0);
-  assert(g.__is_black_ == false);
+  assert(g.__color_ == std::__tree_color::__red);
 
   g.__left_   = &f;
   f.__parent_ = &g;
@@ -1373,22 +1376,22 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &g);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &root);
   assert(g.__left_ == &f);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &g);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == false);
+  assert(f.__color_ == std::__tree_color::__red);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == false);
+  assert(h.__color_ == std::__tree_color::__red);
 
   f.__left_   = &e;
   e.__parent_ = &f;
@@ -1400,27 +1403,27 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &g);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &root);
   assert(g.__left_ == &f);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &g);
   assert(f.__left_ == &e);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &f);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == false);
+  assert(e.__color_ == std::__tree_color::__red);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   e.__left_   = &d;
   d.__parent_ = &e;
@@ -1432,32 +1435,32 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &g);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &root);
   assert(g.__left_ == &e);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &g);
   assert(e.__left_ == &d);
   assert(e.__right_ == &f);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(d.__parent_ == &e);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == false);
+  assert(d.__color_ == std::__tree_color::__red);
 
   assert(f.__parent_ == &e);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == false);
+  assert(f.__color_ == std::__tree_color::__red);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   d.__left_   = &c;
   c.__parent_ = &d;
@@ -1469,37 +1472,37 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &g);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &root);
   assert(g.__left_ == &e);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &g);
   assert(e.__left_ == &d);
   assert(e.__right_ == &f);
-  assert(e.__is_black_ == false);
+  assert(e.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &e);
   assert(d.__left_ == &c);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &d);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == false);
+  assert(c.__color_ == std::__tree_color::__red);
 
   assert(f.__parent_ == &e);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   c.__left_   = &b;
   b.__parent_ = &c;
@@ -1511,42 +1514,42 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &g);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &root);
   assert(g.__left_ == &e);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &g);
   assert(e.__left_ == &c);
   assert(e.__right_ == &f);
-  assert(e.__is_black_ == false);
+  assert(e.__color_ == std::__tree_color::__red);
 
   assert(c.__parent_ == &e);
   assert(c.__left_ == &b);
   assert(c.__right_ == &d);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &c);
   assert(b.__left_ == 0);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == false);
+  assert(b.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &c);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == false);
+  assert(d.__color_ == std::__tree_color::__red);
 
   assert(f.__parent_ == &e);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   b.__left_   = &a;
   a.__parent_ = &b;
@@ -1558,47 +1561,47 @@ void test5() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &e);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(e.__parent_ == &root);
   assert(e.__left_ == &c);
   assert(e.__right_ == &g);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &e);
   assert(c.__left_ == &b);
   assert(c.__right_ == &d);
-  assert(c.__is_black_ == false);
+  assert(c.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &c);
   assert(b.__left_ == &a);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == false);
+  assert(a.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &c);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(g.__parent_ == &e);
   assert(g.__left_ == &f);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == false);
+  assert(g.__color_ == std::__tree_color::__red);
 
   assert(f.__parent_ == &g);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/libcxx/containers/associative/tree_left_rotate.pass.cpp b/libcxx/test/libcxx/containers/associative/tree_left_rotate.pass.cpp
index d97a1c89f1f70..d833bad878317 100644
--- a/libcxx/test/libcxx/containers/associative/tree_left_rotate.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/tree_left_rotate.pass.cpp
@@ -27,6 +27,7 @@ struct Node {
 
   Node* __parent_unsafe() const { return __parent_; }
   void __set_parent(Node* x) { __parent_ = x; }
+  Node* __get_parent() { return __parent_; }
 
   Node() : __left_(), __right_(), __parent_() {}
 };
diff --git a/libcxx/test/libcxx/containers/associative/tree_remove.pass.cpp b/libcxx/test/libcxx/containers/associative/tree_remove.pass.cpp
index e543c3360a685..7eb124bcad451 100644
--- a/libcxx/test/libcxx/containers/associative/tree_remove.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/tree_remove.pass.cpp
@@ -24,12 +24,15 @@ struct Node {
   Node* __left_;
   Node* __right_;
   Node* __parent_;
-  bool __is_black_;
+  std::__tree_color __color_;
 
   Node* __parent_unsafe() const { return __parent_; }
   void __set_parent(Node* x) { __parent_ = x; }
+  Node* __get_parent() { return __parent_; }
+  void __set_color(std::__tree_color __color) { __color_ = __color; }
+  std::__tree_color __get_color() { return __color_; }
 
-  Node() : __left_(), __right_(), __parent_(), __is_black_() {}
+  Node() : __left_(), __right_(), __parent_(), __color_() {}
 };
 
 void test1() {
@@ -48,27 +51,27 @@ void test1() {
     b.__parent_   = &root;
     b.__left_     = &y;
     b.__right_    = &d;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     y.__parent_   = &b;
     y.__left_     = 0;
     y.__right_    = 0;
-    y.__is_black_ = true;
+    y.__color_ = std::__tree_color::__black;
 
     d.__parent_   = &b;
     d.__left_     = &c;
     d.__right_    = &e;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &d;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &d;
     e.__left_     = 0;
     e.__right_    = 0;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     std::__tree_remove(root.__left_, &y);
     assert(std::__tree_invariant(root.__left_));
@@ -76,27 +79,27 @@ void test1() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &d);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(d.__parent_ == &root);
     assert(d.__left_ == &b);
     assert(d.__right_ == &e);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &d);
     assert(b.__left_ == 0);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(e.__parent_ == &d);
     assert(e.__left_ == 0);
     assert(e.__right_ == 0);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
   }
   {
     // Right
@@ -113,55 +116,56 @@ void test1() {
     b.__parent_   = &root;
     b.__right_    = &y;
     b.__left_     = &d;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     y.__parent_   = &b;
     y.__right_    = 0;
     y.__left_     = 0;
-    y.__is_black_ = true;
+    y.__color_ = std::__tree_color::__black;
 
     d.__parent_   = &b;
     d.__right_    = &c;
     d.__left_     = &e;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &d;
     c.__right_    = 0;
     c.__left_     = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &d;
     e.__right_    = 0;
     e.__left_     = 0;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
+    assert(std::__tree_invariant(root.__left_));
     std::__tree_remove(root.__left_, &y);
     assert(std::__tree_invariant(root.__left_));
 
     assert(root.__parent_ == 0);
     assert(root.__left_ == &d);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(d.__parent_ == &root);
     assert(d.__right_ == &b);
     assert(d.__left_ == &e);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(b.__parent_ == &d);
     assert(b.__right_ == 0);
     assert(b.__left_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &b);
     assert(c.__right_ == 0);
     assert(c.__left_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     assert(e.__parent_ == &d);
     assert(e.__right_ == 0);
     assert(e.__left_ == 0);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
   }
   {
     // Left
@@ -179,32 +183,32 @@ void test1() {
     b.__parent_   = &root;
     b.__left_     = &y;
     b.__right_    = &d;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     y.__parent_   = &b;
     y.__left_     = 0;
     y.__right_    = 0;
-    y.__is_black_ = true;
+    y.__color_ = std::__tree_color::__black;
 
     d.__parent_   = &b;
     d.__left_     = &c;
     d.__right_    = &e;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &d;
     c.__left_     = &f;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &d;
     e.__left_     = 0;
     e.__right_    = 0;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &c;
     f.__left_     = 0;
     f.__right_    = 0;
-    f.__is_black_ = false;
+    f.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &y);
     assert(std::__tree_invariant(root.__left_));
@@ -212,32 +216,32 @@ void test1() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &d);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(d.__parent_ == &root);
     assert(d.__left_ == &f);
     assert(d.__right_ == &e);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(f.__parent_ == &d);
     assert(f.__left_ == &b);
     assert(f.__right_ == &c);
-    assert(f.__is_black_ == false);
+    assert(f.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &f);
     assert(b.__left_ == 0);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &f);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(e.__parent_ == &d);
     assert(e.__left_ == 0);
     assert(e.__right_ == 0);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
   }
   {
     // Right
@@ -255,32 +259,32 @@ void test1() {
     b.__parent_   = &root;
     b.__right_    = &y;
     b.__left_     = &d;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     y.__parent_   = &b;
     y.__right_    = 0;
     y.__left_     = 0;
-    y.__is_black_ = true;
+    y.__color_ = std::__tree_color::__black;
 
     d.__parent_   = &b;
     d.__right_    = &c;
     d.__left_     = &e;
-    d.__is_black_ = false;
+    d.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &d;
     c.__right_    = &f;
     c.__left_     = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     e.__parent_   = &d;
     e.__right_    = 0;
     e.__left_     = 0;
-    e.__is_black_ = true;
+    e.__color_ = std::__tree_color::__black;
 
     f.__parent_   = &c;
     f.__right_    = 0;
     f.__left_     = 0;
-    f.__is_black_ = false;
+    f.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &y);
     assert(std::__tree_invariant(root.__left_));
@@ -288,32 +292,32 @@ void test1() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &d);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(d.__parent_ == &root);
     assert(d.__right_ == &f);
     assert(d.__left_ == &e);
-    assert(d.__is_black_ == true);
+    assert(d.__color_ == std::__tree_color::__black);
 
     assert(f.__parent_ == &d);
     assert(f.__right_ == &b);
     assert(f.__left_ == &c);
-    assert(f.__is_black_ == false);
+    assert(f.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &f);
     assert(b.__right_ == 0);
     assert(b.__left_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &f);
     assert(c.__right_ == 0);
     assert(c.__left_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     assert(e.__parent_ == &d);
     assert(e.__right_ == 0);
     assert(e.__left_ == 0);
-    assert(e.__is_black_ == true);
+    assert(e.__color_ == std::__tree_color::__black);
   }
 }
 
@@ -329,17 +333,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     std::__tree_remove(root.__left_, &a);
 
@@ -348,17 +352,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -367,12 +371,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -381,7 +385,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -394,17 +398,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &a);
 
@@ -413,17 +417,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -432,12 +436,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -446,7 +450,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -459,17 +463,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     std::__tree_remove(root.__left_, &a);
 
@@ -478,17 +482,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -497,12 +501,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -511,7 +515,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -524,17 +528,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &a);
 
@@ -543,17 +547,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == &c);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     assert(c.__parent_ == &b);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == false);
+    assert(c.__color_ == std::__tree_color::__red);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -562,12 +566,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -576,7 +580,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -589,17 +593,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     std::__tree_remove(root.__left_, &b);
 
@@ -608,17 +612,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &c);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == &a);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -627,12 +631,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -641,7 +645,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -654,17 +658,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &b);
 
@@ -673,17 +677,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &c);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == &a);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -692,12 +696,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == 0);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -706,7 +710,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -719,17 +723,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     std::__tree_remove(root.__left_, &b);
 
@@ -738,17 +742,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &c);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == &a);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -757,12 +761,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &a);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &root);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == true);
+    assert(a.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -771,7 +775,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -784,17 +788,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &b);
 
@@ -803,17 +807,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &c);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &c);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(c.__parent_ == &root);
     assert(c.__left_ == &a);
     assert(c.__right_ == 0);
-    assert(c.__is_black_ == true);
+    assert(c.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &c);
 
@@ -822,12 +826,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &a);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &root);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == true);
+    assert(a.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -836,7 +840,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -849,17 +853,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     std::__tree_remove(root.__left_, &c);
 
@@ -868,17 +872,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -887,12 +891,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &a);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &root);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == true);
+    assert(a.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -901,7 +905,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -914,17 +918,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &c);
 
@@ -933,17 +937,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -952,12 +956,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &a);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &root);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == true);
+    assert(a.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -966,7 +970,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -979,17 +983,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = true;
+    a.__color_ = std::__tree_color::__black;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = true;
+    c.__color_ = std::__tree_color::__black;
 
     std::__tree_remove(root.__left_, &c);
 
@@ -998,17 +1002,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -1017,12 +1021,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -1031,7 +1035,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
   {
     Node root;
@@ -1044,17 +1048,17 @@ void test2() {
     b.__parent_   = &root;
     b.__left_     = &a;
     b.__right_    = &c;
-    b.__is_black_ = true;
+    b.__color_ = std::__tree_color::__black;
 
     a.__parent_   = &b;
     a.__left_     = 0;
     a.__right_    = 0;
-    a.__is_black_ = false;
+    a.__color_ = std::__tree_color::__red;
 
     c.__parent_   = &b;
     c.__left_     = 0;
     c.__right_    = 0;
-    c.__is_black_ = false;
+    c.__color_ = std::__tree_color::__red;
 
     std::__tree_remove(root.__left_, &c);
 
@@ -1063,17 +1067,17 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(a.__parent_ == &b);
     assert(a.__left_ == 0);
     assert(a.__right_ == 0);
-    assert(a.__is_black_ == false);
+    assert(a.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == &a);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &a);
 
@@ -1082,12 +1086,12 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == &b);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
 
     assert(b.__parent_ == &root);
     assert(b.__left_ == 0);
     assert(b.__right_ == 0);
-    assert(b.__is_black_ == true);
+    assert(b.__color_ == std::__tree_color::__black);
 
     std::__tree_remove(root.__left_, &b);
 
@@ -1096,7 +1100,7 @@ void test2() {
     assert(root.__parent_ == 0);
     assert(root.__left_ == 0);
     assert(root.__right_ == 0);
-    assert(root.__is_black_ == false);
+    assert(root.__color_ == std::__tree_color::__red);
   }
 }
 
@@ -1116,42 +1120,42 @@ void test3() {
   e.__parent_   = &root;
   e.__left_     = &c;
   e.__right_    = &g;
-  e.__is_black_ = true;
+  e.__color_ = std::__tree_color::__black;
 
   c.__parent_   = &e;
   c.__left_     = &b;
   c.__right_    = &d;
-  c.__is_black_ = false;
+  c.__color_ = std::__tree_color::__red;
 
   g.__parent_   = &e;
   g.__left_     = &f;
   g.__right_    = &h;
-  g.__is_black_ = false;
+  g.__color_ = std::__tree_color::__red;
 
   b.__parent_   = &c;
   b.__left_     = &a;
   b.__right_    = 0;
-  b.__is_black_ = true;
+  b.__color_ = std::__tree_color::__black;
 
   d.__parent_   = &c;
   d.__left_     = 0;
   d.__right_    = 0;
-  d.__is_black_ = true;
+  d.__color_ = std::__tree_color::__black;
 
   f.__parent_   = &g;
   f.__left_     = 0;
   f.__right_    = 0;
-  f.__is_black_ = true;
+  f.__color_ = std::__tree_color::__black;
 
   h.__parent_   = &g;
   h.__left_     = 0;
   h.__right_    = 0;
-  h.__is_black_ = true;
+  h.__color_ = std::__tree_color::__black;
 
   a.__parent_   = &b;
   a.__left_     = 0;
   a.__right_    = 0;
-  a.__is_black_ = false;
+  a.__color_ = std::__tree_color::__red;
 
   assert(std::__tree_invariant(root.__left_));
 
@@ -1162,42 +1166,42 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &e);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(e.__parent_ == &root);
   assert(e.__left_ == &c);
   assert(e.__right_ == &g);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &e);
   assert(c.__left_ == &b);
   assert(c.__right_ == &d);
-  assert(c.__is_black_ == false);
+  assert(c.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &e);
   assert(g.__left_ == &f);
   assert(g.__right_ == 0);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &c);
   assert(b.__left_ == &a);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == false);
+  assert(a.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &c);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &g);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == false);
+  assert(f.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &g);
 
@@ -1206,37 +1210,37 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &e);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(e.__parent_ == &root);
   assert(e.__left_ == &c);
   assert(e.__right_ == &f);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &e);
   assert(c.__left_ == &b);
   assert(c.__right_ == &d);
-  assert(c.__is_black_ == false);
+  assert(c.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &c);
   assert(b.__left_ == &a);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == false);
+  assert(a.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &c);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &e);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   std::__tree_remove(root.__left_, &f);
 
@@ -1245,32 +1249,32 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &c);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(c.__parent_ == &root);
   assert(c.__left_ == &b);
   assert(c.__right_ == &e);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &c);
   assert(b.__left_ == &a);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &c);
   assert(e.__left_ == &d);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == false);
+  assert(a.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &e);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == false);
+  assert(d.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &e);
 
@@ -1279,27 +1283,27 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &c);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(c.__parent_ == &root);
   assert(c.__left_ == &b);
   assert(c.__right_ == &d);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &c);
   assert(b.__left_ == &a);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == false);
+  assert(a.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &c);
   assert(d.__left_ == 0);
   assert(d.__right_ == 0);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   std::__tree_remove(root.__left_, &d);
 
@@ -1308,22 +1312,22 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &b);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &root);
   assert(b.__left_ == &a);
   assert(b.__right_ == &c);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &b);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   std::__tree_remove(root.__left_, &c);
 
@@ -1332,17 +1336,17 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &b);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(b.__parent_ == &root);
   assert(b.__left_ == &a);
   assert(b.__right_ == 0);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(a.__parent_ == &b);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == false);
+  assert(a.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &b);
 
@@ -1351,12 +1355,12 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &a);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(a.__parent_ == &root);
   assert(a.__left_ == 0);
   assert(a.__right_ == 0);
-  assert(a.__is_black_ == true);
+  assert(a.__color_ == std::__tree_color::__black);
 
   std::__tree_remove(root.__left_, &a);
 
@@ -1365,7 +1369,7 @@ void test3() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == 0);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 }
 
 void test4() {
@@ -1384,42 +1388,42 @@ void test4() {
   d.__parent_   = &root;
   d.__left_     = &b;
   d.__right_    = &f;
-  d.__is_black_ = true;
+  d.__color_ = std::__tree_color::__black;
 
   b.__parent_   = &d;
   b.__left_     = &a;
   b.__right_    = &c;
-  b.__is_black_ = false;
+  b.__color_ = std::__tree_color::__red;
 
   f.__parent_   = &d;
   f.__left_     = &e;
   f.__right_    = &g;
-  f.__is_black_ = false;
+  f.__color_ = std::__tree_color::__red;
 
   a.__parent_   = &b;
   a.__left_     = 0;
   a.__right_    = 0;
-  a.__is_black_ = true;
+  a.__color_ = std::__tree_color::__black;
 
   c.__parent_   = &b;
   c.__left_     = 0;
   c.__right_    = 0;
-  c.__is_black_ = true;
+  c.__color_ = std::__tree_color::__black;
 
   e.__parent_   = &f;
   e.__left_     = 0;
   e.__right_    = 0;
-  e.__is_black_ = true;
+  e.__color_ = std::__tree_color::__black;
 
   g.__parent_   = &f;
   g.__left_     = 0;
   g.__right_    = &h;
-  g.__is_black_ = true;
+  g.__color_ = std::__tree_color::__black;
 
   h.__parent_   = &g;
   h.__left_     = 0;
   h.__right_    = 0;
-  h.__is_black_ = false;
+  h.__color_ = std::__tree_color::__red;
 
   assert(std::__tree_invariant(root.__left_));
 
@@ -1430,42 +1434,42 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &d);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &root);
   assert(d.__left_ == &b);
   assert(d.__right_ == &f);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(b.__parent_ == &d);
   assert(b.__left_ == 0);
   assert(b.__right_ == &c);
-  assert(b.__is_black_ == true);
+  assert(b.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &d);
   assert(f.__left_ == &e);
   assert(f.__right_ == &g);
-  assert(f.__is_black_ == false);
+  assert(f.__color_ == std::__tree_color::__red);
 
   assert(c.__parent_ == &b);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == false);
+  assert(c.__color_ == std::__tree_color::__red);
 
   assert(e.__parent_ == &f);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(g.__parent_ == &f);
   assert(g.__left_ == 0);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == false);
+  assert(h.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &b);
 
@@ -1474,37 +1478,37 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &d);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(d.__parent_ == &root);
   assert(d.__left_ == &c);
   assert(d.__right_ == &f);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(c.__parent_ == &d);
   assert(c.__left_ == 0);
   assert(c.__right_ == 0);
-  assert(c.__is_black_ == true);
+  assert(c.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &d);
   assert(f.__left_ == &e);
   assert(f.__right_ == &g);
-  assert(f.__is_black_ == false);
+  assert(f.__color_ == std::__tree_color::__red);
 
   assert(e.__parent_ == &f);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(g.__parent_ == &f);
   assert(g.__left_ == 0);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == false);
+  assert(h.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &c);
 
@@ -1513,32 +1517,32 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &f);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(f.__parent_ == &root);
   assert(f.__left_ == &d);
   assert(f.__right_ == &g);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(d.__parent_ == &f);
   assert(d.__left_ == 0);
   assert(d.__right_ == &e);
-  assert(d.__is_black_ == true);
+  assert(d.__color_ == std::__tree_color::__black);
 
   assert(g.__parent_ == &f);
   assert(g.__left_ == 0);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &d);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == false);
+  assert(e.__color_ == std::__tree_color::__red);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == false);
+  assert(h.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &d);
 
@@ -1547,27 +1551,27 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &f);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(f.__parent_ == &root);
   assert(f.__left_ == &e);
   assert(f.__right_ == &g);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(e.__parent_ == &f);
   assert(e.__left_ == 0);
   assert(e.__right_ == 0);
-  assert(e.__is_black_ == true);
+  assert(e.__color_ == std::__tree_color::__black);
 
   assert(g.__parent_ == &f);
   assert(g.__left_ == 0);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == false);
+  assert(h.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &e);
 
@@ -1576,22 +1580,22 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &g);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &root);
   assert(g.__left_ == &f);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(f.__parent_ == &g);
   assert(f.__left_ == 0);
   assert(f.__right_ == 0);
-  assert(f.__is_black_ == true);
+  assert(f.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   std::__tree_remove(root.__left_, &f);
 
@@ -1600,17 +1604,17 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &g);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(g.__parent_ == &root);
   assert(g.__left_ == 0);
   assert(g.__right_ == &h);
-  assert(g.__is_black_ == true);
+  assert(g.__color_ == std::__tree_color::__black);
 
   assert(h.__parent_ == &g);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == false);
+  assert(h.__color_ == std::__tree_color::__red);
 
   std::__tree_remove(root.__left_, &g);
 
@@ -1619,12 +1623,12 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == &h);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 
   assert(h.__parent_ == &root);
   assert(h.__left_ == 0);
   assert(h.__right_ == 0);
-  assert(h.__is_black_ == true);
+  assert(h.__color_ == std::__tree_color::__black);
 
   std::__tree_remove(root.__left_, &h);
 
@@ -1633,7 +1637,7 @@ void test4() {
   assert(root.__parent_ == 0);
   assert(root.__left_ == 0);
   assert(root.__right_ == 0);
-  assert(root.__is_black_ == false);
+  assert(root.__color_ == std::__tree_color::__red);
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/libcxx/containers/associative/tree_right_rotate.pass.cpp b/libcxx/test/libcxx/containers/associative/tree_right_rotate.pass.cpp
index b86446f5be101..25b87c0ccbdcf 100644
--- a/libcxx/test/libcxx/containers/associative/tree_right_rotate.pass.cpp
+++ b/libcxx/test/libcxx/containers/associative/tree_right_rotate.pass.cpp
@@ -27,6 +27,7 @@ struct Node {
 
   Node* __parent_unsafe() const { return __parent_; }
   void __set_parent(Node* x) { __parent_ = x; }
+  Node* __get_parent() { return __parent_; }
 
   Node() : __left_(), __right_(), __parent_() {}
 };



More information about the llvm-branch-commits mailing list