Add remove function to stdext storages

This commit is contained in:
Eduardo Bart
2012-08-17 18:19:51 -03:00
parent e41c8d5805
commit affe641a1f
2 changed files with 32 additions and 1 deletions

View File

@@ -60,6 +60,22 @@ public:
m_values[m_size++] = { id, packed_any(value) };
}
bool remove(Key id) {
auto begin = m_values;
auto end = m_values + m_size;
auto it = std::find_if(begin, end, [=](const value_pair& pair) -> bool { return pair.id == id; } );
if(it == end)
return false;
int pos = it - begin;
auto tmp = new value_pair[m_size-1];
std::copy(begin, begin + pos, tmp);
std::copy(begin + pos + 1, end, tmp + pos);
delete[] m_values;
m_values = tmp;
m_size--;
return true;
}
template<typename T>
T get(Key id) const {
for(SizeType i=0;i<m_size;++i)