28 static_assert(std::is_trivially_constructible_v<T>);
29 static_assert(std::is_trivially_move_constructible_v<T>);
30 static_assert(std::is_trivially_move_assignable_v<T>);
31 static_assert(std::is_trivially_destructible_v<T>);
35 : m_count(0), m_capacity(0), m_data(
nullptr) {}
36 ~QPODVector() {
if (m_data) ::free(m_data); }
38 const T &at(
int idx)
const {
42 T &operator[](
int idx) {
50 void prepend(
const T &v) {
54 void append(
const T &v) {
58 void insert(
int idx,
const T &v) {
59 if (m_count == m_capacity) {
60 m_capacity += Increment;
61 m_data = (T *)realloc(
static_cast<
void *>(m_data), m_capacity *
sizeof(T));
63 int moveCount = m_count - idx;
65 ::memmove(
static_cast<
void *>(m_data + idx + 1),
static_cast<
const void *>(m_data + idx), moveCount *
sizeof(T));
70 void reserve(
int count) {
71 if (count >= m_capacity) {
72 m_capacity = (count + (Increment-1)) & (0xFFFFFFFF - Increment + 1);
73 m_data = (T *)realloc(
static_cast<
void *>(m_data), m_capacity *
sizeof(T));
77 void insertBlank(
int idx,
int count) {
78 int newSize = m_count + count;
80 int moveCount = m_count - idx;
82 ::memmove(
static_cast<
void *>(m_data + idx + count),
static_cast<
const void *>(m_data + idx),
83 moveCount *
sizeof(T));
87 void remove(
int idx,
int count = 1) {
88 int moveCount = m_count - (idx + count);
90 ::memmove(
static_cast<
void *>(m_data + idx),
static_cast<
const void *>(m_data + idx + count),
91 moveCount *
sizeof(T));
95 void removeOne(
const T &v) {
97 while (idx < m_count) {
98 if (m_data[idx] == v) {
106 int find(
const T &v) {
107 for (
int idx = 0; idx < m_count; ++idx)
108 if (m_data[idx] == v)
113 bool contains(
const T &v) {
114 return find(v) != -1;
121 void copyAndClear(QPODVector<T,Increment> &other) {
122 if (other.m_data) ::free(other.m_data);
123 other.m_count = m_count;
124 other.m_capacity = m_capacity;
125 other.m_data = m_data;
131 QPODVector<T,Increment> &operator<<(
const T &v) { append(v);
return *
this; }
133 Q_DISABLE_COPY(QPODVector)