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