From c0e92eb2a15963f410010b04ec7dc9bd90e8a248 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 31 Oct 2018 17:54:57 -0700 Subject: [PATCH] ircd::fs: Add boolean operators for fd. --- include/ircd/fs/fd.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/include/ircd/fs/fd.h b/include/ircd/fs/fd.h index c561e1e32..84a4fd919 100644 --- a/include/ircd/fs/fd.h +++ b/include/ircd/fs/fd.h @@ -29,10 +29,9 @@ struct ircd::fs::fd int fdno{-1}; public: - operator const int &() const - { - return fdno; - } + operator const int &() const; + operator bool() const; + bool operator!() const; fd(const string_view &path, const opts &); fd(const string_view &path); @@ -69,3 +68,24 @@ struct ircd::fs::fd::opts opts(const std::ios::openmode &); opts() = default; }; + +inline bool +ircd::fs::fd::operator!() +const +{ + return !bool(*this); +} + +inline ircd::fs::fd::operator +bool() +const +{ + return int(*this) >= 0; +} + +inline ircd::fs::fd::operator +const int &() +const +{ + return fdno; +}