Add QArrayDataOps::moveAppend()

Same as copyAppend() but calls the move constructor

Change-Id: I7de033f80b0e4431b7f1ffff13f9399e39b5fee4
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
bb10
Thiago Macieira 2015-08-10 15:15:07 -07:00 committed by Lars Knoll
parent 8f3189f7a2
commit f2569c0ff7
1 changed files with 56 additions and 0 deletions

View File

@ -83,6 +83,9 @@ struct QPodArrayOps
this->size += e - b;
}
void moveAppend(T *b, T *e)
{ copyAppend(b, e); }
void copyAppend(size_t n, parameter_type t)
{
Q_ASSERT(this->isMutable());
@ -176,6 +179,20 @@ struct QGenericArrayOps
}
}
void moveAppend(T *b, T *e)
{
Q_ASSERT(this->isMutable() || b == e);
Q_ASSERT(!this->isShared() || b == e);
Q_ASSERT(b <= e);
Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size);
T *iter = this->end();
for (; b != e; ++iter, ++b) {
new (iter) T(std::move(*b));
++this->size;
}
}
void copyAppend(size_t n, parameter_type t)
{
Q_ASSERT(this->isMutable());
@ -414,6 +431,45 @@ struct QMovableArrayOps
(--e)->~T();
} while (e != b);
}
void moveAppend(T *b, T *e)
{
Q_ASSERT(this->isMutable());
Q_ASSERT(!this->isShared());
Q_ASSERT(b <= e);
Q_ASSERT(e <= this->begin() || b > this->end()); // No overlap
Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size);
// Provides strong exception safety guarantee,
// provided T::~T() nothrow
struct CopyConstructor
{
CopyConstructor(T *w) : where(w) {}
void copy(const T *src, const T *const srcEnd)
{
n = 0;
for (; src != srcEnd; ++src) {
new (where + n) T(std::move(*src));
++n;
}
n = 0;
}
~CopyConstructor()
{
while (n)
where[--n].~T();
}
T *const where;
size_t n;
} copier(this->end());
copier.copy(b, e);
this->size += (e - b);
}
};
template <class T, class = void>