forked from organicmaps/organicmaps
Added emplace_back to buffer_vector.
This commit is contained in:
parent
e82d3af67e
commit
65251a9d86
2 changed files with 25 additions and 3 deletions
|
@ -275,8 +275,8 @@ typedef buffer_vector<CopyCtorChecker, 2> VectorT;
|
|||
VectorT GetVector()
|
||||
{
|
||||
VectorT v;
|
||||
v.push_back("0");
|
||||
v.push_back("1");
|
||||
v.emplace_back("0");
|
||||
v.emplace_back("1");
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -294,7 +294,7 @@ UNIT_TEST(BufferVectorMove)
|
|||
VectorT v1 = GetVector();
|
||||
TestVector(v1, 2);
|
||||
|
||||
v1.push_back("2");
|
||||
v1.emplace_back("2");
|
||||
TestVector(v1, 3);
|
||||
|
||||
VectorT v2(move(v1));
|
||||
|
|
|
@ -316,6 +316,28 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
void emplace_back(Args &&... args)
|
||||
{
|
||||
if (IsDynamic())
|
||||
m_dynamic.emplace_back(args...);
|
||||
else
|
||||
{
|
||||
if (m_size < N)
|
||||
{
|
||||
value_type v(args...);
|
||||
Swap(v, m_static[m_size++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT_EQUAL(m_size, N, ());
|
||||
SwitchToDynamic();
|
||||
m_dynamic.emplace_back(args...);
|
||||
ASSERT_EQUAL(m_dynamic.size(), N + 1, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IterT> void insert(const_iterator where, IterT beg, IterT end)
|
||||
{
|
||||
ptrdiff_t const pos = where - data();
|
||||
|
|
Loading…
Add table
Reference in a new issue