Quellcode durchsuchen

feat(containers): make destructors constexpr

greatbridf vor 2 Jahren
Ursprung
Commit
5e395c9d64

+ 2 - 2
include/types/cplusplus.hpp

@@ -99,12 +99,12 @@ public:
 
 namespace types {
 template <typename T>
-T&& move(T& val)
+constexpr T&& move(T& val)
 {
     return static_cast<T&&>(val);
 }
 template <typename T>
-T&& forward(typename traits::remove_reference<T>::type& val)
+constexpr T&& forward(typename traits::remove_reference<T>::type& val)
 {
     return static_cast<T&&>(val);
 }

+ 1 - 1
include/types/hash_map.hpp

@@ -221,7 +221,7 @@ public:
     {
     }
 
-    ~hash_map()
+    constexpr ~hash_map()
     {
         buckets.clear();
     }

+ 1 - 1
include/types/list.hpp

@@ -217,7 +217,7 @@ public:
         return *this;
     }
 
-    ~list() noexcept
+    constexpr ~list() noexcept
     {
         destroy();
     }

+ 17 - 17
include/types/string.hpp

@@ -17,17 +17,17 @@ public:
     static inline constexpr size_type npos = (-1U);
 
 public:
-    explicit string(size_type capacity = 8)
+    explicit constexpr string(size_type capacity = 8)
         : inner_vector_type(capacity)
     {
         this->push_back(0x00);
     }
-    string(const char* str, size_type n = npos)
+    constexpr string(const char* str, size_type n = npos)
         : string()
     {
         this->append(str, n);
     }
-    string& append(const char* str, size_type n = npos)
+    constexpr string& append(const char* str, size_type n = npos)
     {
         this->pop_back();
 
@@ -39,51 +39,51 @@ public:
         this->push_back(0x00);
         return *this;
     }
-    string& append(const string& str)
+    constexpr string& append(const string& str)
     {
         return this->append(str.data());
     }
-    string& append(string&& str)
+    constexpr string& append(string&& str)
     {
         return this->append(str.data());
     }
-    string& operator+=(const char c)
+    constexpr string& operator+=(const char c)
     {
         this->pop_back();
         this->push_back(c);
         this->push_back(0x00);
         return *this;
     }
-    string& operator+=(const char* str)
+    constexpr string& operator+=(const char* str)
     {
         return this->append(str);
     }
-    string& operator+=(const string& str)
+    constexpr string& operator+=(const string& str)
     {
         return this->append(str);
     }
-    string& operator+=(string&& str)
+    constexpr string& operator+=(string&& str)
     {
         return this->append(move(str));
     }
-    bool operator==(const string& rhs) const
+    constexpr bool operator==(const string& rhs) const
     {
         return strcmp(c_str(), rhs.c_str()) == 0;
     }
-    string substr(size_type pos, size_type n = npos)
+    constexpr string substr(size_type pos, size_type n = npos)
     {
         return string(this->m_arr + pos, n);
     }
-    const char* c_str(void) const noexcept
+    constexpr const char* c_str(void) const noexcept
     {
         return this->data();
     }
-    void clear(void)
+    constexpr void clear(void)
     {
         inner_vector_type::clear();
         this->push_back(0x00);
     }
-    char pop(void)
+    constexpr char pop(void)
     {
         this->pop_back();
         auto iter = inner_vector_type::back();
@@ -91,21 +91,21 @@ public:
         *iter = 0x00;
         return c;
     }
-    typename inner_vector_type::iterator_type back(void)
+    constexpr typename inner_vector_type::iterator_type back(void)
     {
         // TODO: assert
         if (this->empty())
             return typename inner_vector_type::iterator_type((void*)0xffffffff);
         return --inner_vector_type::back();
     }
-    typename inner_vector_type::const_iterator_type back(void) const
+    constexpr typename inner_vector_type::const_iterator_type back(void) const
     {
         // TODO: assert
         if (this->empty())
             return typename inner_vector_type::iterator_type((void*)0xffffffff);
         return --inner_vector_type::back();
     }
-    typename inner_vector_type::const_iterator_type cback(void) const
+    constexpr typename inner_vector_type::const_iterator_type cback(void) const
     {
         // TODO: assert
         if (this->empty())

+ 1 - 1
include/types/vector.hpp

@@ -159,7 +159,7 @@ public:
         return operator=(vector(arr));
     }
 
-    ~vector() noexcept
+    constexpr ~vector() noexcept
     {
         resize(0);
     }