From 514aeead63e56240083b931aa36864a74f9d2f11 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 2 Oct 2012 14:18:34 +0200 Subject: [PATCH] do not use our broken safe bool, c++11 explicit bool conversion is better --- src/context.hh | 10 +++++----- src/units.hh | 1 + src/utils.hh | 4 +--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/context.hh b/src/context.hh index 05acef73..ecca3137 100644 --- a/src/context.hh +++ b/src/context.hh @@ -32,7 +32,7 @@ struct Context throw runtime_error("no buffer in context"); return m_editor->buffer(); } - bool has_buffer() const { return m_editor; } + bool has_buffer() const { return (bool)m_editor; } Editor& editor() const { @@ -40,7 +40,7 @@ struct Context throw runtime_error("no editor in context"); return *m_editor.get(); } - bool has_editor() const { return m_editor; } + bool has_editor() const { return (bool)m_editor; } Window& window() const { @@ -48,7 +48,7 @@ struct Context throw runtime_error("no window in context"); return *dynamic_cast(m_editor.get()); } - bool has_window() const { return m_editor and dynamic_cast(m_editor.get()); } + bool has_window() const { return (bool)m_editor and dynamic_cast(m_editor.get()); } Client& client() const { @@ -56,7 +56,7 @@ struct Context throw runtime_error("no client in context"); return *m_client; } - bool has_client() const { return m_client; } + bool has_client() const { return (bool)m_client; } UserInterface& ui() const { @@ -64,7 +64,7 @@ struct Context throw runtime_error("no user interface in context"); return *m_ui; } - bool has_ui() const { return m_ui; } + bool has_ui() const { return (bool)m_ui; } void change_editor(Editor& editor) { diff --git a/src/units.hh b/src/units.hh index b9def254..f5137e99 100644 --- a/src/units.hh +++ b/src/units.hh @@ -71,6 +71,7 @@ public: { return !m_value; } explicit constexpr operator ValueType() const { return m_value; } + explicit constexpr operator bool() const { return m_value; } private: ValueType m_value; }; diff --git a/src/utils.hh b/src/utils.hh index 92c09767..73bd6276 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -54,8 +54,6 @@ T* Singleton::ms_instance = nullptr; // *** safe_ptr: objects that assert nobody references them when they die *** -typedef void* (*unspecified_bool_type)(); - template class safe_ptr { @@ -106,7 +104,7 @@ public: T* get() const { return m_ptr; } - operator unspecified_bool_type() const { return (unspecified_bool_type)(m_ptr); } + explicit operator bool() const { return m_ptr; } private: T* m_ptr;