[gtksourceviewmm] Markup: Change operator bool() to operator const void*().



commit 6137772d56c419739d91fbde3b43a040062750a8
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Apr 4 22:19:23 2011 +0200

    Markup: Change operator bool() to operator const void*().
    
    This matches the recent change in gtkmm, which avoids an
    unwanted implicit cast to int and is generally considered
    good C++ practice.

 gtksourceview/gtksourceviewmm/markup.cc |    4 ++--
 gtksourceview/gtksourceviewmm/markup.h  |   12 +++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/gtksourceviewmm/markup.cc b/gtksourceview/gtksourceviewmm/markup.cc
index 6346af1..6864fda 100644
--- a/gtksourceview/gtksourceviewmm/markup.cc
+++ b/gtksourceview/gtksourceviewmm/markup.cc
@@ -52,9 +52,9 @@ Markup& Markup::operator=(const Markup& other)
   return *this;
 }
 
-Markup::operator bool() const
+Markup::operator const void*() const
 {
-  return !(markup_.empty());
+  return (const void*)!(markup_.empty());
 }
 
 bool Markup::equal(const Markup& rhs) const
diff --git a/gtksourceview/gtksourceviewmm/markup.h b/gtksourceview/gtksourceviewmm/markup.h
index df4aa3e..20a841f 100644
--- a/gtksourceview/gtksourceviewmm/markup.h
+++ b/gtksourceview/gtksourceviewmm/markup.h
@@ -87,13 +87,23 @@ public:
    */
   Markup& operator=(const Markup& other);
 
+  /** This typedef is just to make it more obvious that 
+   * our operator const void*() should be used like operator bool().
+   */ 
+  typedef const void* BoolExpr;
+
   /** Checks if Markup is not empty.
+   * For instance,
+   * @code
+   * if(markup)
+   *   do_something()
+   * @endcode
    *
    * @return @c true if Markup is not empty, otherwise @c false.
    *
    * @newin{2,10}
    */
-  operator bool() const;
+  operator BoolExpr() const;
 
   /** Checks if @a other Markup is the same as this one.
    *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]