diff options
Diffstat (limited to 'gdb/common')
-rw-r--r-- | gdb/common/gdb_vecs.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gdb/common/gdb_vecs.h b/gdb/common/gdb_vecs.h index 29db27a..7318e53 100644 --- a/gdb/common/gdb_vecs.h +++ b/gdb/common/gdb_vecs.h @@ -50,4 +50,35 @@ extern void dirnames_to_char_ptr_vec_append extern std::vector<gdb::unique_xmalloc_ptr<char>> dirnames_to_char_ptr_vec (const char *dirnames); +/* Remove the element at position IX from VEC, not preserving the order of the + remaining elements. Return the removed element. */ + +template <typename T> +T +unordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix) +{ + gdb_assert (ix < vec.size ()); + + T removed = std::move (vec[ix]); + vec[ix] = std::move (vec.back ()); + vec.pop_back (); + + return removed; +} + +/* Remove the element at position IX from VEC, preserving the order the + remaining elements. Return the removed element. */ + +template <typename T> +T +ordered_remove (std::vector<T> &vec, typename std::vector<T>::size_type ix) +{ + gdb_assert (ix < vec.size ()); + + T removed = std::move (vec[ix]); + vec.erase (vec.begin () + ix); + + return removed; +} + #endif /* GDB_VECS_H */ |