@@ -488,7 +488,7 @@ bool GlobalCache<Metavariables>::mutable_cache_item_is_ready(
488488 optional_callback->register_with_charm ();
489489 // Second mutex is for vector of callbacks
490490 std::mutex& mutex = tuples::get<MutexTag<tag>>(mutexes_).second ;
491- std::unique_ptr<Callback> clone_of_optional_callback =
491+ const std::unique_ptr<Callback> clone_of_optional_callback =
492492 optional_callback->get_clone ();
493493 {
494494 // Scoped for lock guard
@@ -559,20 +559,17 @@ bool GlobalCache<Metavariables>::mutable_cache_item_is_ready(
559559 // It's possible that no new callbacks were registered, so make sure this
560560 // array component id still has callbacks before trying to remove them.
561561 if (callbacks.contains (array_component_id)) {
562+ // If this callback was a duplicate, we'll have to search through all
563+ // callbacks to determine which to remove. If it wasn't a duplicate,
564+ // then it'll just be the last callback in the vector.
565+ auto & vec_callbacks = callbacks.at (array_component_id);
566+ std::erase_if (vec_callbacks,
567+ [&clone_of_optional_callback](const auto & t) {
568+ return t->is_equal_to (*clone_of_optional_callback);
569+ });
570+
562571 if (callbacks.at (array_component_id).empty ()) {
563572 callbacks.erase (array_component_id);
564- } else {
565- // If this callback was a duplicate, we'll have to search through all
566- // callbacks to determine which to remove. If it wasn't a dupliate,
567- // then it'll just be the last callback in the vector.
568- auto & vec_callbacks = callbacks.at (array_component_id);
569- auto it_to_erase = vec_callbacks.begin ();
570- for (; it_to_erase != vec_callbacks.end (); it_to_erase++) {
571- if ((*it_to_erase)->is_equal_to (*clone_of_optional_callback)) {
572- vec_callbacks.erase (it_to_erase);
573- break ;
574- }
575- }
576573 }
577574 }
578575 }
0 commit comments