From dc39e377e1a3923e63569020beb29f9662c1a3ee Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 4 Jan 2017 11:31:47 -0800 Subject: Add missing operator<() to CFX_RetainPtr. Use std::less<>() rather than a direct ptr1 < ptr2 comparison to be strictly correct in face of unspecified behaviour when ptr1 and ptr2 don't point within the same "object" (e.g. segment of memory on a brain-dead segmented architecture). This will allow their use as keys in maps. Review-Url: https://codereview.chromium.org/2616683002 --- core/fxcrt/cfx_retain_ptr.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core/fxcrt/cfx_retain_ptr.h') diff --git a/core/fxcrt/cfx_retain_ptr.h b/core/fxcrt/cfx_retain_ptr.h index 1b137d4974..f70faf1464 100644 --- a/core/fxcrt/cfx_retain_ptr.h +++ b/core/fxcrt/cfx_retain_ptr.h @@ -5,11 +5,13 @@ #ifndef CORE_FXCRT_CFX_RETAIN_PTR_H_ #define CORE_FXCRT_CFX_RETAIN_PTR_H_ +#include #include #include #include "core/fxcrt/fx_memory.h" +// Analogous to base's scoped_refptr. template class CFX_RetainPtr { public: @@ -50,9 +52,12 @@ class CFX_RetainPtr { bool operator==(const CFX_RetainPtr& that) const { return Get() == that.Get(); } - bool operator!=(const CFX_RetainPtr& that) const { return !(*this == that); } + bool operator<(const CFX_RetainPtr& that) const { + return std::less()(Get(), that.Get()); + } + explicit operator bool() const { return !!m_pObj; } T& operator*() const { return *m_pObj.get(); } T* operator->() const { return m_pObj.get(); } -- cgit v1.2.3