From 109334de27c41273089c81ff20bae938ef763f23 Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Mon, 12 Sep 2016 17:53:09 -0700 Subject: [PATCH] Fix TLObserver copy constructor Reviewed By: yfeldblum Differential Revision: D3853494 fbshipit-source-id: 23f5cadcb55a9307fb2a825fe4c53a03c5978d12 --- folly/experimental/observer/Observer-inl.h | 4 ++++ folly/experimental/observer/Observer.h | 1 + folly/experimental/observer/test/ObserverTest.cpp | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/folly/experimental/observer/Observer-inl.h b/folly/experimental/observer/Observer-inl.h index eb1338d7..a73033c4 100644 --- a/folly/experimental/observer/Observer-inl.h +++ b/folly/experimental/observer/Observer-inl.h @@ -58,6 +58,10 @@ TLObserver::TLObserver(Observer observer) : observer_(observer), snapshot_([&] { return new Snapshot(observer_.getSnapshot()); }) {} +template +TLObserver::TLObserver(const TLObserver& other) + : TLObserver(other.observer_) {} + template const Snapshot& TLObserver::getSnapshotRef() const { auto& snapshot = *snapshot_; diff --git a/folly/experimental/observer/Observer.h b/folly/experimental/observer/Observer.h index 8037b24d..bad88e14 100644 --- a/folly/experimental/observer/Observer.h +++ b/folly/experimental/observer/Observer.h @@ -158,6 +158,7 @@ template class TLObserver { public: explicit TLObserver(Observer observer); + TLObserver(const TLObserver& other); const Snapshot& getSnapshotRef() const; const Snapshot& operator*() const { diff --git a/folly/experimental/observer/test/ObserverTest.cpp b/folly/experimental/observer/test/ObserverTest.cpp index c2be17b9..f540ffa9 100644 --- a/folly/experimental/observer/test/ObserverTest.cpp +++ b/folly/experimental/observer/test/ObserverTest.cpp @@ -248,3 +248,15 @@ TEST(Observer, Stress) { } }); } + +TEST(Observer, TLObserver) { + auto createTLObserver = [](int value) { + return folly::observer::makeTLObserver([=] { return value; }); + }; + + auto k = + std::make_unique>(createTLObserver(42)); + EXPECT_EQ(42, ***k); + k = std::make_unique>(createTLObserver(41)); + EXPECT_EQ(41, ***k); +} -- 2.34.1