watchable-impl
Hleb Valoshka 2019-04-16 13:14:30 +03:00
parent 4a2bd133e0
commit bf1844a2f5
1 changed files with 5 additions and 5 deletions

View File

@ -3,14 +3,15 @@
#include "watcher.h"
#include <vector>
#include <cassert>
#include <algorithm>
//namespace celutil
//{
template<typename T> class Watchable
{
public:
void addWatcher(Watcher<T>* watcher);
void removeWatcher(Watcher<T>* watcher);
inline void addWatcher(Watcher<T>* watcher);
inline void removeWatcher(Watcher<T>* watcher);
void notifyWatchers(int) const;
private:
std::vector<Watcher<T>*> watchers;
@ -24,9 +25,8 @@ template<typename T> void Watchable<T>::addWatcher(Watcher<T>* watcher)
template<typename T> void Watchable<T>::removeWatcher(Watcher<T>* watcher)
{
auto iter = find(watchers.begin(), watchers.end(), watcher);
if (iter != watchers.end())
watchers.erase(iter);
std::remove_if(watchers.begin(), watchers.end(),
[&watcher](Watcher<T>* w) { return w == watcher; });
}
template<typename T> void Watchable<T>::notifyWatchers(int property) const