trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: Cleanup of bool conversion in Ptr.h for C++11.
Date Wed, 06 Dec 2017 20:08:50 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new e8f7a85  Cleanup of bool conversion in Ptr.h for C++11.
e8f7a85 is described below

commit e8f7a859e54f6ac68af63b754524d45502fb8d80
Author: Walt Karas <wkaras@yahoo-inc.com>
AuthorDate: Mon Oct 16 21:32:42 2017 +0000

    Cleanup of bool conversion in Ptr.h for C++11.
---
 lib/ts/Ptr.h       | 14 +++++---------
 lib/ts/test_Ptr.cc |  2 +-
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index 188723b..3c3c9fd 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -1,6 +1,6 @@
 /** @file
 
-  A brief file description
+  Reference-counting shared pointer, like std::shared_ptr.
 
   @section license License
 
@@ -100,13 +100,6 @@ private:
 ////////////////////////////////////////////////////////////////////////
 template <class T> class Ptr
 {
-  // https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool.
-  typedef void (Ptr::*bool_type)() const;
-  void
-  this_type_does_not_support_comparisons() const
-  {
-  }
-
 public:
   explicit Ptr(T *p = 0);
   Ptr(const Ptr<T> &);
@@ -118,7 +111,10 @@ public:
 
   T *operator->() const { return (m_ptr); }
   T &operator*() const { return (*m_ptr); }
-  operator bool_type() const { return m_ptr ? &Ptr::this_type_does_not_support_comparisons
: 0; }
+
+  // Making this explicit avoids unwanted conversions.  See https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool
.
+  explicit operator bool() const { return m_ptr != nullptr; }
+
   int
   operator==(const T *p)
   {
diff --git a/lib/ts/test_Ptr.cc b/lib/ts/test_Ptr.cc
index 9392bf2..9acd4c8 100644
--- a/lib/ts/test_Ptr.cc
+++ b/lib/ts/test_Ptr.cc
@@ -95,5 +95,5 @@ REGRESSION_TEST(Ptr_bool)(RegressionTest *t, int /* atype ATS_UNUSED */,
int *ps
   Ptr<PtrObject> some = make_ptr(new PtrObject(&alive));
 
   box.check(!none, "Empty Ptr<T> is false");
-  box.check(some, "Non-empty Ptr<T> is true");
+  box.check(bool(some), "Non-empty Ptr<T> is true");
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message