fd: Make it possible to test fd existence
Change-Id: I85f205bd97c4168729961c68ad74ec15eda1cd12
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include-fd/stdplus/fd/dupable.hpp b/include-fd/stdplus/fd/dupable.hpp
index 0f810cf..f45575d 100644
--- a/include-fd/stdplus/fd/dupable.hpp
+++ b/include-fd/stdplus/fd/dupable.hpp
@@ -49,6 +49,7 @@
[[nodiscard]] int release();
int get() const override;
+ explicit operator bool() const noexcept;
private:
friend class ManagedFd;
diff --git a/include-fd/stdplus/fd/managed.hpp b/include-fd/stdplus/fd/managed.hpp
index a188421..4554785 100644
--- a/include-fd/stdplus/fd/managed.hpp
+++ b/include-fd/stdplus/fd/managed.hpp
@@ -51,6 +51,7 @@
[[nodiscard]] int release();
int get() const override;
+ explicit operator bool() const noexcept;
private:
detail::ManagedFdHandle handle;
diff --git a/src/fd/dupable.cpp b/src/fd/dupable.cpp
index d096d04..e9b0982 100644
--- a/src/fd/dupable.cpp
+++ b/src/fd/dupable.cpp
@@ -39,5 +39,10 @@
return handle.value();
}
+DupableFd::operator bool() const noexcept
+{
+ return static_cast<bool>(handle);
+}
+
} // namespace fd
} // namespace stdplus
diff --git a/src/fd/managed.cpp b/src/fd/managed.cpp
index 5669903..b9cfa87 100644
--- a/src/fd/managed.cpp
+++ b/src/fd/managed.cpp
@@ -55,5 +55,10 @@
return handle.value();
}
+ManagedFd::operator bool() const noexcept
+{
+ return static_cast<bool>(handle);
+}
+
} // namespace fd
} // namespace stdplus