Pārlūkot izejas kodu

feat(map): add operator bool, fix find()

greatbridf 2 gadi atpakaļ
vecāks
revīzija
0120d746b3
1 mainītis faili ar 8 papildinājumiem un 4 dzēšanām
  1. 8 4
      include/types/map.hpp

+ 8 - 4
include/types/map.hpp

@@ -357,6 +357,11 @@ public:
 
 
             return ret;
             return ret;
         }
         }
+
+        constexpr operator bool(void)
+        {
+            return p;
+        }
     };
     };
 
 
     using iterator_type = iterator<false>;
     using iterator_type = iterator<false>;
@@ -472,10 +477,7 @@ private:
     {
     {
         node* cur = root;
         node* cur = root;
 
 
-        if (unlikely(!cur))
-            return nullptr;
-
-        for (;;) {
+        for (; cur;) {
             if (cur->v.key == key)
             if (cur->v.key == key)
                 return cur;
                 return cur;
 
 
@@ -484,6 +486,8 @@ private:
             else
             else
                 cur = cur->right;
                 cur = cur->right;
         }
         }
+
+        return nullptr;
     }
     }
 
 
     // this function DOES NOT dellocate the node
     // this function DOES NOT dellocate the node