Explorar el Código

feat(string): impl. clear() and c_str()

greatbridf hace 2 años
padre
commit
a1dfcee9b7
Se han modificado 2 ficheros con 16 adiciones y 0 borrados
  1. 9 0
      include/types/string.hpp
  2. 7 0
      include/types/vector.hpp

+ 9 - 0
include/types/string.hpp

@@ -65,6 +65,15 @@ public:
     {
         return string(this->m_arr + pos, n);
     }
+    const char* c_str(void) const noexcept
+    {
+        return this->data();
+    }
+    void clear(void)
+    {
+        inner_vector_type::clear();
+        this->push_back(0x00);
+    }
 };
 } // namespace types
 

+ 7 - 0
include/types/vector.hpp

@@ -273,6 +273,13 @@ public:
         return size() == 0;
     }
 
+    void clear(void)
+    {
+        for (size_t i = 0; i < size(); ++i)
+            allocator_traits<allocator_type>::deconstruct(m_arr + i);
+        m_size = 0;
+    }
+
     // TODO
 
     // iterator_type r_start() noexcept;