use erase_if

This commit is contained in:
Ari Lazier 2016-08-03 14:43:28 -07:00
parent 5dc7b2f414
commit 0074bdfe94
2 changed files with 11 additions and 19 deletions

View File

@ -274,18 +274,14 @@ void ListClass<T>::remove_listener(ContextType ctx, ObjectType this_object, size
auto list = get_internal<T, ListClass<T>>(this_object); auto list = get_internal<T, ListClass<T>>(this_object);
auto callback = Value::validated_to_function(ctx, arguments[0]); auto callback = Value::validated_to_function(ctx, arguments[0]);
auto protected_function = Protected<FunctionType>(ctx, callback); auto protected_function = Protected<FunctionType>(ctx, callback);
auto iter = list->m_notification_tokens.begin();
typename Protected<FunctionType>::Comparator compare; typename Protected<FunctionType>::Comparator compare;
while (iter != list->m_notification_tokens.end()) { list->m_notification_tokens.erase(
if(compare(iter->first, protected_function)) { std::remove_if(list->m_notification_tokens.begin(),
iter = list->m_notification_tokens.erase(iter); list->m_notification_tokens.end(),
} [&](const auto & o) { return compare(o.first, protected_function); }),
else { list->m_notification_tokens.end());
iter++;
}
}
} }
template<typename T> template<typename T>

View File

@ -261,16 +261,12 @@ void ResultsClass<T>::remove_listener(ContextType ctx, ObjectType this_object, s
auto callback = Value::validated_to_function(ctx, arguments[0]); auto callback = Value::validated_to_function(ctx, arguments[0]);
auto protected_function = Protected<FunctionType>(ctx, callback); auto protected_function = Protected<FunctionType>(ctx, callback);
auto iter = results->m_notification_tokens.begin();
typename Protected<FunctionType>::Comparator compare; typename Protected<FunctionType>::Comparator compare;
while (iter != results->m_notification_tokens.end()) { results->m_notification_tokens.erase(
if(compare(iter->first, protected_function)) { std::remove_if(results->m_notification_tokens.begin(),
iter = results->m_notification_tokens.erase(iter); results->m_notification_tokens.end(),
} [&](const auto & o) { return compare(o.first, protected_function); }),
else { results->m_notification_tokens.end());
iter++;
}
}
} }
template<typename T> template<typename T>