/* Some commonly-used VEC types.
- Copyright (C) 2012-2018 Free Software Foundation, Inc.
+ Copyright (C) 2012-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "vec.h"
-typedef const char *const_char_ptr;
-
-DEF_VEC_P (const_char_ptr);
-
/* Split STR, a list of DELIMITER-separated fields, into a char pointer vector.
You may modify the returned strings. */
extern std::vector<gdb::unique_xmalloc_ptr<char>>
dirnames_to_char_ptr_vec (const char *dirnames);
+/* Remove the element pointed by iterator IT 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>::iterator it)
+{
+ gdb_assert (it >= vec.begin () && it < vec.end ());
+
+ T removed = std::move (*it);
+ *it = std::move (vec.back ());
+ vec.pop_back ();
+
+ return removed;
+}
+
/* Remove the element at position IX from VEC, not preserving the order of the
remaining elements. Return the removed element. */
{
gdb_assert (ix < vec.size ());
- T removed = std::move (vec[ix]);
- vec[ix] = std::move (vec.back ());
- vec.pop_back ();
-
- return removed;
+ return unordered_remove (vec, vec.begin () + ix);
}
/* Remove the element at position IX from VEC, preserving the order the