diff options
Diffstat (limited to 'core/templates/local_vector.h')
-rw-r--r-- | core/templates/local_vector.h | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index b454821a8f..e0047e0782 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -41,7 +41,7 @@ // If tight, it grows strictly as much as needed. // Otherwise, it grows exponentially (the default and what you want in most cases). -template <class T, class U = uint32_t, bool force_trivial = false, bool tight = false> +template <typename T, typename U = uint32_t, bool force_trivial = false, bool tight = false> class LocalVector { private: U count = 0; @@ -64,7 +64,7 @@ public: CRASH_COND_MSG(!data, "Out of memory"); } - if constexpr (!std::is_trivially_constructible<T>::value && !force_trivial) { + if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) { memnew_placement(&data[count++], T(p_elem)); } else { data[count++] = p_elem; @@ -77,7 +77,7 @@ public: for (U i = p_index; i < count; i++) { data[i] = data[i + 1]; } - if constexpr (!std::is_trivially_destructible<T>::value && !force_trivial) { + if constexpr (!std::is_trivially_destructible_v<T> && !force_trivial) { data[count].~T(); } } @@ -90,7 +90,7 @@ public: if (count > p_index) { data[p_index] = data[count]; } - if constexpr (!std::is_trivially_destructible<T>::value && !force_trivial) { + if constexpr (!std::is_trivially_destructible_v<T> && !force_trivial) { data[count].~T(); } } @@ -104,6 +104,22 @@ public: return false; } + U erase_multiple_unordered(const T &p_val) { + U from = 0; + U occurrences = 0; + while (true) { + int64_t idx = find(p_val, from); + + if (idx == -1) { + break; + } + remove_at_unordered(idx); + from = idx; + occurrences++; + } + return occurrences; + } + void invert() { for (U i = 0; i < count / 2; i++) { SWAP(data[i], data[count - i - 1]); @@ -133,7 +149,7 @@ public: _FORCE_INLINE_ U size() const { return count; } void resize(U p_size) { if (p_size < count) { - if constexpr (!std::is_trivially_destructible<T>::value && !force_trivial) { + if constexpr (!std::is_trivially_destructible_v<T> && !force_trivial) { for (U i = p_size; i < count; i++) { data[i].~T(); } @@ -145,7 +161,7 @@ public: data = (T *)memrealloc(data, capacity * sizeof(T)); CRASH_COND_MSG(!data, "Out of memory"); } - if constexpr (!std::is_trivially_constructible<T>::value && !force_trivial) { + if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) { for (U i = count; i < p_size; i++) { memnew_placement(&data[i], T); } @@ -248,7 +264,7 @@ public: return -1; } - template <class C> + template <typename C> void sort_custom() { U len = count; if (len == 0) { @@ -322,7 +338,7 @@ public: } }; -template <class T, class U = uint32_t, bool force_trivial = false> +template <typename T, typename U = uint32_t, bool force_trivial = false> using TightLocalVector = LocalVector<T, U, force_trivial, true>; #endif // LOCAL_VECTOR_H |