Added VectorRef::emplace_back
Also added VectorRef::emplace_back_deep.
This commit is contained in:
parent
c01a345652
commit
57fbc1a074
21
flow/Arena.h
21
flow/Arena.h
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue