forked from organicmaps/organicmaps
Add buffer_vector::append().
This commit is contained in:
parent
096b42db2c
commit
05da4a8e57
2 changed files with 41 additions and 3 deletions
|
@ -168,6 +168,33 @@ UNIT_TEST(BufferVectorInsert)
|
|||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(BufferVectorAppend)
|
||||
{
|
||||
for (size_t initialLength = 0; initialLength < 20; ++initialLength)
|
||||
{
|
||||
for (size_t insertLength = 0; insertLength < 20; ++insertLength)
|
||||
{
|
||||
buffer_vector<char, 5> b;
|
||||
vector<char> v;
|
||||
for (size_t i = 0; i < initialLength; ++i)
|
||||
{
|
||||
b.push_back('A' + i);
|
||||
v.push_back('A' + i);
|
||||
}
|
||||
|
||||
vector<int> dataToInsert(insertLength);
|
||||
for (size_t i = 0; i < insertLength; ++i)
|
||||
dataToInsert[i] = 'a' + i;
|
||||
|
||||
b.append(dataToInsert.begin(), dataToInsert.end());
|
||||
v.insert(v.end(), dataToInsert.begin(), dataToInsert.end());
|
||||
|
||||
vector<char> result(b.begin(), b.end());
|
||||
TEST_EQUAL(v, result, (initialLength, insertLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(BufferVectorPopBack)
|
||||
{
|
||||
for (size_t len = 1; len < 6; ++len)
|
||||
|
|
|
@ -34,13 +34,12 @@ public:
|
|||
}
|
||||
|
||||
template <typename IterT>
|
||||
void assign(IterT beg, IterT end)
|
||||
void append(IterT beg, IterT end)
|
||||
{
|
||||
if (m_size == USE_DYNAMIC)
|
||||
m_dynamic.assign(beg, end);
|
||||
m_dynamic.insert(m_dynamic.end(), beg, end);
|
||||
else
|
||||
{
|
||||
m_size = 0;
|
||||
while (beg != end)
|
||||
{
|
||||
if (m_size == N)
|
||||
|
@ -56,6 +55,18 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
template <typename IterT>
|
||||
void assign(IterT beg, IterT end)
|
||||
{
|
||||
if (m_size == USE_DYNAMIC)
|
||||
m_dynamic.assign(beg, end);
|
||||
else
|
||||
{
|
||||
m_size = 0;
|
||||
append(beg, end);
|
||||
}
|
||||
}
|
||||
|
||||
void reserve(size_t n)
|
||||
{
|
||||
if (m_size == USE_DYNAMIC || n > N)
|
||||
|
|
Loading…
Add table
Reference in a new issue