]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/outcome/experimental/status-code/posix_code.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / outcome / experimental / status-code / posix_code.hpp
index a8e7011c057f692ad284c2d94f4b503ff4f466ba..4d3d9f011f6b8e6b0fdc9eafc38e72a1aa8022e6 100644 (file)
@@ -35,7 +35,7 @@ DEALINGS IN THE SOFTWARE.
 #error <posix_code.hpp> is not includable when BOOST_OUTCOME_SYSTEM_ERROR2_NOT_POSIX is defined!
 #endif
 
-#include "generic_code.hpp"
+#include "quick_status_code_from_enum.hpp"
 
 #include <cstring>  // for strchr and strerror_r
 
@@ -47,8 +47,19 @@ using posix_code = status_code<_posix_code_domain>;
 //! A specialisation of `status_error` for the POSIX error code domain.
 using posix_error = status_error<_posix_code_domain>;
 
+namespace mixins
+{
+  template <class Base> struct mixin<Base, _posix_code_domain> : public Base
+  {
+    using Base::Base;
+
+    //! Returns a `posix_code` for the current value of `errno`.
+    static posix_code current() noexcept;
+  };
+}  // namespace mixins
+
 /*! The implementation of the domain for POSIX error codes, those returned by `errno`.
-*/
+ */
 class _posix_code_domain : public status_code_domain
 {
   template <class DomainType> friend class status_code;
@@ -61,7 +72,7 @@ class _posix_code_domain : public status_code_domain
 #ifdef _WIN32
     strerror_s(buffer, sizeof(buffer), c);
 #elif defined(__gnu_linux__) && !defined(__ANDROID__)  // handle glibc's weird strerror_r()
-    char *s = strerror_r(c, buffer, sizeof(buffer));   // NOLINT
+    char *s = strerror_r(c, buffer, sizeof(buffer));  // NOLINT
     if(s != nullptr)
     {
       strncpy(buffer, s, sizeof(buffer));  // NOLINT
@@ -70,7 +81,7 @@ class _posix_code_domain : public status_code_domain
 #else
     strerror_r(c, buffer, sizeof(buffer));
 #endif
-    size_t length = strlen(buffer);  // NOLINT
+    size_t length = strlen(buffer);                     // NOLINT
     auto *p = static_cast<char *>(malloc(length + 1));  // NOLINT
     if(p == nullptr)
     {
@@ -86,7 +97,10 @@ public:
   using _base::string_ref;
 
   //! Default constructor
-  constexpr explicit _posix_code_domain(typename _base::unique_id_type id = 0xa59a56fe5f310933) noexcept : _base(id) {}
+  constexpr explicit _posix_code_domain(typename _base::unique_id_type id = 0xa59a56fe5f310933) noexcept
+      : _base(id)
+  {
+  }
   _posix_code_domain(const _posix_code_domain &) = default;
   _posix_code_domain(_posix_code_domain &&) = default;
   _posix_code_domain &operator=(const _posix_code_domain &) = default;
@@ -100,12 +114,12 @@ public:
 protected:
   virtual bool _do_failure(const status_code<void> &code) const noexcept override  // NOLINT
   {
-    assert(code.domain() == *this);  // NOLINT
+    assert(code.domain() == *this);                             // NOLINT
     return static_cast<const posix_code &>(code).value() != 0;  // NOLINT
   }
   virtual bool _do_equivalent(const status_code<void> &code1, const status_code<void> &code2) const noexcept override  // NOLINT
   {
-    assert(code1.domain() == *this);  // NOLINT
+    assert(code1.domain() == *this);                          // NOLINT
     const auto &c1 = static_cast<const posix_code &>(code1);  // NOLINT
     if(code2.domain() == *this)
     {
@@ -124,20 +138,20 @@ protected:
   }
   virtual generic_code _generic_code(const status_code<void> &code) const noexcept override  // NOLINT
   {
-    assert(code.domain() == *this);  // NOLINT
+    assert(code.domain() == *this);                         // NOLINT
     const auto &c = static_cast<const posix_code &>(code);  // NOLINT
     return generic_code(static_cast<errc>(c.value()));
   }
   virtual string_ref _do_message(const status_code<void> &code) const noexcept override  // NOLINT
   {
-    assert(code.domain() == *this);  // NOLINT
+    assert(code.domain() == *this);                         // NOLINT
     const auto &c = static_cast<const posix_code &>(code);  // NOLINT
     return _make_string_ref(c.value());
   }
 #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
   BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN virtual void _do_throw_exception(const status_code<void> &code) const override  // NOLINT
   {
-    assert(code.domain() == *this);  // NOLINT
+    assert(code.domain() == *this);                         // NOLINT
     const auto &c = static_cast<const posix_code &>(code);  // NOLINT
     throw status_error<_posix_code_domain>(c);
   }
@@ -150,6 +164,11 @@ inline constexpr const _posix_code_domain &_posix_code_domain::get()
   return posix_code_domain;
 }
 
+namespace mixins
+{
+  template <class Base> inline posix_code mixin<Base, _posix_code_domain>::current() noexcept { return posix_code(errno); }
+}  // namespace mixins
+
 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
 
 #endif