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
11 #include "common/assert.h"
13 namespace bt2_common {
16 * Moves the last entry of `vec` to the index `idx`, then removes the last entry.
18 * Meant to be a direct replacement for g_ptr_array_remove_index_fast(), but for
21 template <typename T, typename AllocatorT>
22 void vectorFastRemove(std::vector<T, AllocatorT>& vec,
23 const typename std::vector<T, AllocatorT>::size_type idx)
25 BT_ASSERT_DBG(idx < vec.size());
27 if (idx < vec.size() - 1) {
28 vec[idx] = std::move(vec.back());
34 } /* namespace bt2_common */
36 #endif /* SRC_CPP_COMMON_VECTOR_HPP */