MCPcopy Create free account
hub / github.com/Apress/design-patterns-in-modern-cpp / notify

Method notify

Behavioral/Observer/observer2.cpp:80–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 vector<PersonListener*> listeners;
79
80 void notify(const string& property_name, const any new_value)
81 {
82 lock_guard<mutex> guard{ mtx };
83 for (const auto listener : listeners)
84 if (listener)
85 listener->person_changed(*this, property_name, new_value);
86
87 // erase-remove
88 listeners.erase(
89 remove(listeners.begin(), listeners.end(), nullptr),
90 listeners.end()
91 );
92 }
93
94 // std::list (easier to remove elements)
95 // concurrent_vector? yes, but no easy erase-remove

Callers

nothing calls this directly

Calls 3

person_changedMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected