Ver Fonte

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

greatbridf há 2 anos atrás
pai
commit
a1dfcee9b7
2 ficheiros alterados com 16 adições e 0 exclusões
  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;