mirror of
https://github.com/edubart/otclient.git
synced 2025-12-16 05:39:47 +01:00
Add remove function to stdext storages
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user