29 static_assert(std::is_trivially_constructible_v<T>);
30 static_assert(std::is_trivially_move_constructible_v<T>);
31 static_assert(std::is_trivially_move_assignable_v<T>);
32 static_assert(std::is_trivially_destructible_v<T>);
36 : m_count(0), m_capacity(0), m_data(
nullptr) {}
37 ~QPODVector() {
if (m_data) ::free(m_data); }
39 const T &at(
int idx)
const {
43 T &operator[](
int idx) {
51 void prepend(
const T &v) {
55 void append(
const T &v) {
59 void insert(
int idx,
const T &v) {
60 if (m_count == m_capacity) {
61 m_capacity += Increment;
62 m_data = (T *)realloc(
static_cast<
void *>(m_data), m_capacity *
sizeof(T));
64 int moveCount = m_count - idx;
66 ::memmove(
static_cast<
void *>(m_data + idx + 1),
static_cast<
const void *>(m_data + idx), moveCount *
sizeof(T));
71 void reserve(
int count) {
72 if (count >= m_capacity) {
73 m_capacity = (count + (Increment-1)) & (0xFFFFFFFF - Increment + 1);
74 m_data = (T *)realloc(
static_cast<
void *>(m_data), m_capacity *
sizeof(T));
78 void insertBlank(
int idx,
int count) {
79 int newSize = m_count + count;
81 int moveCount = m_count - idx;
83 ::memmove(
static_cast<
void *>(m_data + idx + count),
static_cast<
const void *>(m_data + idx),
84 moveCount *
sizeof(T));
88 void remove(
int idx,
int count = 1) {
89 int moveCount = m_count - (idx + count);
91 ::memmove(
static_cast<
void *>(m_data + idx),
static_cast<
const void *>(m_data + idx + count),
92 moveCount *
sizeof(T));
96 void removeOne(
const T &v) {
98 while (idx < m_count) {
99 if (m_data[idx] == v) {
107 int find(
const T &v) {
108 for (
int idx = 0; idx < m_count; ++idx)
109 if (m_data[idx] == v)
114 bool contains(
const T &v) {
115 return find(v) != -1;
122 void copyAndClear(QPODVector<T,Increment> &other) {
123 if (other.m_data) ::free(other.m_data);
124 other.m_count = m_count;
125 other.m_capacity = m_capacity;
126 other.m_data = m_data;
132 QPODVector<T,Increment> &operator<<(
const T &v) { append(v);
return *
this; }
134 Q_DISABLE_COPY(QPODVector)