vector move ctor + emplace_back

master
Daniel Kolesa 2015-04-14 23:04:51 +01:00
parent f70d8e792d
commit 2f56d5b52b
1 changed files with 12 additions and 0 deletions

View File

@ -33,6 +33,11 @@ namespace octa {
*this = v;
}
Vector(Vector &&v): p_buf(v.p_buf), p_len(v.p_len), p_cap(v.p_cap) {
v.p_buf = NULL;
v.p_len = v.p_cap = 0;
}
~Vector() {
clear();
}
@ -139,6 +144,13 @@ namespace octa {
return p_buf[p_len++];
}
template<typename ...U>
T &emplace_back(U &&...args) {
if (p_len == p_cap) reserve(p_len + 1);
new (&p_buf[p_len]) T(args...);
return p_buf[p_len++];
}
void pop() {
if (octa::IsClass<T>::value) {
p_buf[--p_len].~T();