diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 9df0dd5..4d4d7f7 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -295,6 +295,11 @@ class QPDFObjectHandle QPDF_DLL QPDFObjectHandle& operator=(QPDFObjectHandle const&) = default; + // Return true if the QPDFObjectHandle is initialized. This allows object handles to be used in + // if statements with initializer. + QPDF_DLL + explicit inline operator bool() const noexcept; + QPDF_DLL inline bool isInitialized() const; @@ -1634,5 +1639,10 @@ QPDFObjectHandle::isInitialized() const return obj != nullptr; } +inline QPDFObjectHandle::operator bool() const noexcept +{ + return static_cast(obj); +} + #endif // QPDF_FUTURE #endif // QPDFOBJECTHANDLE_HH diff --git a/include/qpdf/QPDFObjectHandle_future.hh b/include/qpdf/QPDFObjectHandle_future.hh index 2a8a0ba..e6a79f6 100644 --- a/include/qpdf/QPDFObjectHandle_future.hh +++ b/include/qpdf/QPDFObjectHandle_future.hh @@ -295,6 +295,11 @@ class QPDFObjectHandle QPDF_DLL QPDFObjectHandle& operator=(QPDFObjectHandle&&) = default; + // Return true if the QPDFObjectHandle is initialized. This allows object handles to be used in + // if statements with initializer. + QPDF_DLL + explicit inline operator bool() const noexcept; + QPDF_DLL inline bool isInitialized() const noexcept; @@ -1634,4 +1639,9 @@ QPDFObjectHandle::isInitialized() const noexcept return obj != nullptr; } +inline QPDFObjectHandle::operator bool() const noexcept +{ + return static_cast(obj); +} + #endif // QPDFOBJECTHANDLE_FUTURE_HH