Require explicit handle validation

Using operator bool() hid ambiguity when handle was polymorfic with
bool.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2025-06-09 22:37:08 +02:00
parent f1e894aefd
commit 47d10e2d78
2 changed files with 5 additions and 3 deletions

View File

@ -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;

View File

@ -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