do not use our broken safe bool, c++11 explicit bool conversion is better

This commit is contained in:
Maxime Coste 2012-10-02 14:18:34 +02:00
parent 9ae8f5e47b
commit 514aeead63
3 changed files with 7 additions and 8 deletions

View File

@ -32,7 +32,7 @@ struct Context
throw runtime_error("no buffer in context"); throw runtime_error("no buffer in context");
return m_editor->buffer(); return m_editor->buffer();
} }
bool has_buffer() const { return m_editor; } bool has_buffer() const { return (bool)m_editor; }
Editor& editor() const Editor& editor() const
{ {
@ -40,7 +40,7 @@ struct Context
throw runtime_error("no editor in context"); throw runtime_error("no editor in context");
return *m_editor.get(); return *m_editor.get();
} }
bool has_editor() const { return m_editor; } bool has_editor() const { return (bool)m_editor; }
Window& window() const Window& window() const
{ {
@ -48,7 +48,7 @@ struct Context
throw runtime_error("no window in context"); throw runtime_error("no window in context");
return *dynamic_cast<Window*>(m_editor.get()); return *dynamic_cast<Window*>(m_editor.get());
} }
bool has_window() const { return m_editor and dynamic_cast<Window*>(m_editor.get()); } bool has_window() const { return (bool)m_editor and dynamic_cast<Window*>(m_editor.get()); }
Client& client() const Client& client() const
{ {
@ -56,7 +56,7 @@ struct Context
throw runtime_error("no client in context"); throw runtime_error("no client in context");
return *m_client; return *m_client;
} }
bool has_client() const { return m_client; } bool has_client() const { return (bool)m_client; }
UserInterface& ui() const UserInterface& ui() const
{ {
@ -64,7 +64,7 @@ struct Context
throw runtime_error("no user interface in context"); throw runtime_error("no user interface in context");
return *m_ui; return *m_ui;
} }
bool has_ui() const { return m_ui; } bool has_ui() const { return (bool)m_ui; }
void change_editor(Editor& editor) void change_editor(Editor& editor)
{ {

View File

@ -71,6 +71,7 @@ public:
{ return !m_value; } { return !m_value; }
explicit constexpr operator ValueType() const { return m_value; } explicit constexpr operator ValueType() const { return m_value; }
explicit constexpr operator bool() const { return m_value; }
private: private:
ValueType m_value; ValueType m_value;
}; };

View File

@ -54,8 +54,6 @@ T* Singleton<T>::ms_instance = nullptr;
// *** safe_ptr: objects that assert nobody references them when they die *** // *** safe_ptr: objects that assert nobody references them when they die ***
typedef void* (*unspecified_bool_type)();
template<typename T> template<typename T>
class safe_ptr class safe_ptr
{ {
@ -106,7 +104,7 @@ public:
T* get() const { return m_ptr; } 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: private:
T* m_ptr; T* m_ptr;