Browse Source

Added Insert in tuple array

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
2aa7a33aca
2 changed files with 41 additions and 0 deletions
  1. +16
    -0
      src/lol/base/array.h
  2. +25
    -0
      src/t/base/array.cpp

+ 16
- 0
src/lol/base/array.h View File

@@ -481,6 +481,22 @@ public:
}
++this->m_count;
}
inline void Insert(ptrdiff_t pos, T... args)
{
ASSERT(pos >= 0);
ASSERT(pos <= m_count);

if (m_count >= m_reserved)
Grow();

for (ptrdiff_t i = m_count; i > pos; --i)
{
new (&m_data[i]) element_t(m_data[i - 1]);
m_data[i - 1].~element_t();
}
new (&this->m_data[pos]) tuple<T...>({ args... });
++m_count;
}
};

template<typename T>


+ 25
- 0
src/t/base/array.cpp View File

@@ -188,6 +188,31 @@ lolunit_declare_fixture(ArrayTest)
lolunit_assert_equal(7, a[2]);
lolunit_assert_equal(2, a[3]);
lolunit_assert_equal(6, a[4]);

array<int, int, int> b;
b.Insert(0, 5, 6, 7);
lolunit_assert_equal(5, b[0].m1);
lolunit_assert_equal(6, b[0].m2);
lolunit_assert_equal(7, b[0].m3);

b.Insert(1, 8, 9, 6);
lolunit_assert_equal(5, b[0].m1);
lolunit_assert_equal(6, b[0].m2);
lolunit_assert_equal(7, b[0].m3);
lolunit_assert_equal(8, b[1].m1);
lolunit_assert_equal(9, b[1].m2);
lolunit_assert_equal(6, b[1].m3);

b.Insert(1, 4, 5, 3);
lolunit_assert_equal(5, b[0].m1);
lolunit_assert_equal(6, b[0].m2);
lolunit_assert_equal(7, b[0].m3);
lolunit_assert_equal(4, b[2].m1);
lolunit_assert_equal(5, b[2].m2);
lolunit_assert_equal(3, b[2].m3);
lolunit_assert_equal(8, b[2].m1);
lolunit_assert_equal(9, b[2].m2);
lolunit_assert_equal(6, b[2].m3);
}

lolunit_declare_test(ArrayConcat)


Loading…
Cancel
Save