From 47d10e2d783ebbd540e14df522489274dcf6f11d Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 9 Jun 2025 22:37:08 +0200 Subject: [PATCH] Require explicit handle validation Using operator bool() hid ambiguity when handle was polymorfic with bool. Signed-off-by: Simon Rozman --- include/stdex/stream.hpp | 6 ++++-- include/stdex/system.hpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/stdex/stream.hpp b/include/stdex/stream.hpp index a35001429..60162e38e 100644 --- a/include/stdex/stream.hpp +++ b/include/stdex/stream.hpp @@ -2421,7 +2421,9 @@ namespace stdex /// /// Returns true if socket handle is valid /// - operator bool() const noexcept { return m_h != stdex::invalid_socket; } + /// \note Implementing `operator bool() const` would be correct C++ approach here. Unfortunately, compiler would prefer it where `socket_t` is expected. + /// + bool valid() const noexcept { return m_h != stdex::invalid_socket; } /// /// Returns socket handle @@ -3219,7 +3221,7 @@ namespace stdex /// /// Returns true if file has a valid handle /// - operator bool() const noexcept { return m_source; } + bool valid() const noexcept { return m_source.valid(); } protected: file m_source; diff --git a/include/stdex/system.hpp b/include/stdex/system.hpp index a8da26f54..d7ee4b081 100644 --- a/include/stdex/system.hpp +++ b/include/stdex/system.hpp @@ -193,7 +193,7 @@ namespace stdex /// /// Returns true if object has a valid handle /// - operator bool() const noexcept { return m_h != TR::invalid_handle; } + bool valid() const noexcept { return m_h != TR::invalid_handle; } /// /// Returns object handle