You still have the problem of increasing your iterator twice when you erase an object.
Common ways are either if/else (if -> erase, else -> increment) or erasing a tmp iterator (auto tmp = iter++).
Ah, derp. So it'd have to be:
void VirtualKey::unbind(const Binding& binding) {
for(auto iter = m_bindings.begin(), end = m_bindings.end(); iter != end; ) {
if((iter->device == binding.device) && (iter->diKey == binding.diKey)) {
iter = m_bindings.erase(iter);
}
else {
++iter;
}
}
}
So I still can't nice-looking syntax with erase. -.-
You could always use the Std lib Algorithm's to side step the mistakes
m_bindings.erase(std::remove_if(std::begin(m_bindings), std::end(m_bindings), [&binding](Binding &b) { return (b.device == binding.device) && (b.diKey == binding.diKey); }) , std::end(m_bindings));
Can't bring myself to do it.