forked from OctaForge/libostd
move stuff instead of copy, forward correctly in emplace_back
This commit is contained in:
parent
2f56d5b52b
commit
d26db78f0d
|
@ -116,7 +116,7 @@ namespace octa {
|
||||||
} else {
|
} else {
|
||||||
T *cur = p_buf, *tcur = tmp, *last = tmp + p_len;
|
T *cur = p_buf, *tcur = tmp, *last = tmp + p_len;
|
||||||
while (tcur != last) {
|
while (tcur != last) {
|
||||||
new (tcur++) T(*cur);
|
new (tcur++) T(move(*cur));
|
||||||
(*cur).~T();
|
(*cur).~T();
|
||||||
++cur;
|
++cur;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ namespace octa {
|
||||||
template<typename ...U>
|
template<typename ...U>
|
||||||
T &emplace_back(U &&...args) {
|
T &emplace_back(U &&...args) {
|
||||||
if (p_len == p_cap) reserve(p_len + 1);
|
if (p_len == p_cap) reserve(p_len + 1);
|
||||||
new (&p_buf[p_len]) T(args...);
|
new (&p_buf[p_len]) T(forward<U>(args)...);
|
||||||
return p_buf[p_len++];
|
return p_buf[p_len++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue