2 * SPDX-FileCopyrightText: 2022 Simon Marchi <simon.marchi@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef SRC_CPP_COMMON_VECTOR_HPP
8 #define SRC_CPP_COMMON_VECTOR_HPP
12 #include "common/assert.h"
17 * Moves the last entry of `vec` to the index `idx`, then removes the last entry.
19 * Meant to be a direct replacement for g_ptr_array_remove_index_fast(), but for
22 template <typename T, typename AllocatorT>
23 void vectorFastRemove(std::vector<T, AllocatorT>& vec,
24 const typename std::vector<T, AllocatorT>::size_type idx)
26 BT_ASSERT_DBG(idx < vec.size());
28 if (idx < vec.size() - 1) {
29 vec[idx] = std::move(vec.back());
35 } /* namespace bt2c */
37 #endif /* SRC_CPP_COMMON_VECTOR_HPP */