Add explicit conversion operator to RetainPtr for easier use in C++11 environments
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 23 Sep 2012 06:56:53 +0000 (06:56 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 23 Sep 2012 06:56:53 +0000 (06:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97403

Reviewed by Dan Bernstein.

* wtf/Compiler.h:
Add support for COMPILER_SUPPORTS(CXX_EXPLICIT_CONVERSIONS)

* wtf/RetainPtr.h:
(RetainPtr):
(WTF::RetainPtr::get):
(WTF::RetainPtr::operator PtrType):
Add the explicit conversion operator and group all the underlying
pointer accessors together.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@129314 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/Compiler.h
Source/WTF/wtf/RetainPtr.h

index 9287c92..e167bbc 100644 (file)
@@ -1,3 +1,20 @@
+2012-09-22  Sam Weinig  <sam@webkit.org>
+
+        Add explicit conversion operator to RetainPtr for easier use in C++11 environments
+        https://bugs.webkit.org/show_bug.cgi?id=97403
+
+        Reviewed by Dan Bernstein.
+
+        * wtf/Compiler.h:
+        Add support for COMPILER_SUPPORTS(CXX_EXPLICIT_CONVERSIONS)
+
+        * wtf/RetainPtr.h:
+        (RetainPtr):
+        (WTF::RetainPtr::get):
+        (WTF::RetainPtr::operator PtrType):
+        Add the explicit conversion operator and group all the underlying
+        pointer accessors together.
+
 2012-09-21  Simon Hausmann  <simon.hausmann@digia.com>
 
         [Qt] Error out early if we don't have ICU available
index f40e15e..e3e18a8 100644 (file)
 
 #define WTF_COMPILER_SUPPORTS_CXX_DELETED_FUNCTIONS __has_extension(cxx_deleted_functions)
 #define WTF_COMPILER_SUPPORTS_CXX_NULLPTR __has_feature(cxx_nullptr)
+#define WTF_COMPILER_SUPPORTS_CXX_EXPLICIT_CONVERSIONS __has_feature(cxx_explicit_conversions)
 #define WTF_COMPILER_SUPPORTS_BLOCKS __has_feature(blocks)
 #define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT __has_extension(c_static_assert)
 #define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL __has_extension(cxx_override_control)
-
 #define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
 
 #endif
index a348957..b2f2e94 100644 (file)
@@ -76,14 +76,16 @@ namespace WTF {
         ~RetainPtr() { if (PtrType ptr = m_ptr) CFRelease(ptr); }
         
         template<typename U> RetainPtr(const RetainPtr<U>&);
-        
-        PtrType get() const { return m_ptr; }
 
         void clear();
         PtrType leakRef() WARN_UNUSED_RETURN;
 
+        PtrType get() const { return m_ptr; }
         PtrType operator->() const { return m_ptr; }
-        
+#if COMPILER_SUPPORTS(CXX_EXPLICIT_CONVERSIONS)
+        explicit operator PtrType() const { return m_ptr; }
+#endif
+
         bool operator!() const { return !m_ptr; }
     
         // This conversion operator allows implicit conversion to bool but not to other integer types.