add copy-constructor version of Observer::Target::Notify
This commit is contained in:
parent
eafa05fbf5
commit
3089bccf55
@ -49,7 +49,7 @@ class Taker : public Dealer<T>, public Observer<T>::Target {
|
||||
public:
|
||||
explicit Taker(const DealerMeta& meta = {}) noexcept : Dealer<T>(meta) { }
|
||||
|
||||
void Take(const T& v) noexcept { Notify(v); }
|
||||
void Take(const T& v) noexcept { Observer<T>::Target::Notify(v); }
|
||||
};
|
||||
|
||||
} // namespace nf7
|
||||
|
@ -48,6 +48,15 @@ class Observer<T>::Target {
|
||||
Target& operator=(Target&&) = delete;
|
||||
|
||||
protected:
|
||||
void Notify(const T& v) noexcept {
|
||||
assert(!calling_observer_ && "do not call Notify from observer callback");
|
||||
|
||||
calling_observer_ = true;
|
||||
for (auto obs : obs_) {
|
||||
obs->Notify(v);
|
||||
}
|
||||
calling_observer_ = false;
|
||||
}
|
||||
void Notify(T&& v) noexcept {
|
||||
assert(!calling_observer_ && "do not call Notify from observer callback");
|
||||
|
||||
@ -58,12 +67,7 @@ class Observer<T>::Target {
|
||||
calling_observer_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
calling_observer_ = true;
|
||||
for (auto obs : obs_) {
|
||||
obs->Notify(v);
|
||||
}
|
||||
calling_observer_ = false;
|
||||
Notify(v);
|
||||
}
|
||||
|
||||
bool observed(const T* = nullptr) const noexcept { return !obs_.empty(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user