Added VectorRef::emplace_back

Also added VectorRef::emplace_back_deep.
This commit is contained in:
sfc-gh-tclinkenbeard 2020-06-19 19:28:39 -07:00
parent c01a345652
commit 57fbc1a074
1 changed files with 21 additions and 0 deletions

View File

@ -910,6 +910,16 @@ public:
VPS::add(*ptr); VPS::add(*ptr);
m_size++; m_size++;
} }
template<class... Us>
T &emplace_back(Arena& p, Us&& ... args) {
if (m_size + 1 > m_capacity) reallocate(p, m_size + 1);
auto ptr = new (&data[m_size]) T(std::forward<Us>(args)...);
VPS::add(*ptr);
m_size++;
return *ptr;
}
// invokes the "Deep copy constructor" T(Arena&, const T&) moving T entirely into arena // invokes the "Deep copy constructor" T(Arena&, const T&) moving T entirely into arena
void push_back_deep(Arena& p, const T& value) { void push_back_deep(Arena& p, const T& value) {
if (m_size + 1 > m_capacity) reallocate(p, m_size + 1); if (m_size + 1 > m_capacity) reallocate(p, m_size + 1);
@ -917,6 +927,17 @@ public:
VPS::add(*ptr); VPS::add(*ptr);
m_size++; m_size++;
} }
// invokes the "Deep copy constructor" T(Arena&, U&&) moving T entirely into arena
template<class... Us>
T &emplace_back_deep(Arena& p, Us&& ... args) {
if (m_size + 1 > m_capacity) reallocate(p, m_size + 1);
auto ptr = new (&data[m_size]) T(p, std::forward<Us>(args)...);
VPS::add(*ptr);
m_size++;
return *ptr;
}
void append(Arena& p, const T* begin, int count) { void append(Arena& p, const T* begin, int count) {
if (m_size + count > m_capacity) reallocate(p, m_size + count); if (m_size + count > m_capacity) reallocate(p, m_size + count);
VPS::invalidate(); VPS::invalidate();