.gitignore: add some more IDE / tools related file
[babeltrace.git] / src / cpp-common / bt2c / vector.hpp
CommitLineData
53118ba6
PP
1/*
2 * SPDX-FileCopyrightText: 2022 Simon Marchi <simon.marchi@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
ae2be88d
SM
7#ifndef BABELTRACE_CPP_COMMON_BT2C_VECTOR_HPP
8#define BABELTRACE_CPP_COMMON_BT2C_VECTOR_HPP
519e0bfe
SM
9
10#include <vector>
c802cacb 11
519e0bfe
SM
12#include "common/assert.h"
13
094bf3f2 14namespace bt2c {
519e0bfe
SM
15
16/*
17 * Moves the last entry of `vec` to the index `idx`, then removes the last entry.
18 *
19 * Meant to be a direct replacement for g_ptr_array_remove_index_fast(), but for
20 * `std::vector`.
21 */
22template <typename T, typename AllocatorT>
23void vectorFastRemove(std::vector<T, AllocatorT>& vec,
24 const typename std::vector<T, AllocatorT>::size_type idx)
25{
26 BT_ASSERT_DBG(idx < vec.size());
27
28 if (idx < vec.size() - 1) {
29 vec[idx] = std::move(vec.back());
30 }
31
32 vec.pop_back();
33}
34
094bf3f2 35} /* namespace bt2c */
519e0bfe 36
ae2be88d 37#endif /* BABELTRACE_CPP_COMMON_BT2C_VECTOR_HPP */
This page took 0.035546 seconds and 4 git commands to generate.