summaryrefslogtreecommitdiff
path: root/core/fxcrt/maybe_owned.h
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-21 20:30:39 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-21 20:30:39 +0000
commit2696aa066d9bd10641e4d88cb3c020af7b8086b3 (patch)
treeb1dbf073215a8a4e63eef4047f36a50bf902db6b /core/fxcrt/maybe_owned.h
parentdc2bb9ad21a10550fb451d7c842c63cbce98045b (diff)
downloadpdfium-2696aa066d9bd10641e4d88cb3c020af7b8086b3.tar.xz
Allow creation of a MaybeOwned<T> from UnownedPtr<T>.
Small test to show these forms compile and do not transfer ownership. Change-Id: I1787a57d4d0bf70da7b6101c1f958cfe9a8f9dda Reviewed-on: https://pdfium-review.googlesource.com/40830 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/maybe_owned.h')
-rw-r--r--core/fxcrt/maybe_owned.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/core/fxcrt/maybe_owned.h b/core/fxcrt/maybe_owned.h
index d920ea7a91..ac3a81d47e 100644
--- a/core/fxcrt/maybe_owned.h
+++ b/core/fxcrt/maybe_owned.h
@@ -24,6 +24,7 @@ class MaybeOwned {
public:
MaybeOwned() : m_pObj(nullptr) {}
explicit MaybeOwned(T* ptr) : m_pObj(ptr) {}
+ explicit MaybeOwned(const UnownedPtr<T>& ptr) : m_pObj(ptr.Get()) {}
explicit MaybeOwned(std::unique_ptr<T, D> ptr)
: m_pOwnedObj(std::move(ptr)), m_pObj(m_pOwnedObj.get()) {}
@@ -74,6 +75,10 @@ class MaybeOwned {
Reset(ptr);
return *this;
}
+ MaybeOwned& operator=(const UnownedPtr<T>& ptr) {
+ Reset(ptr.Get());
+ return *this;
+ }
MaybeOwned& operator=(std::unique_ptr<T, D> ptr) {
Reset(std::move(ptr));
return *this;