From c02cd2b0042bc8ab3827e36a0faf04bff325d024 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 19 Sep 2021 05:24:08 +0300 Subject: [PATCH] Add private error_code::equals, use it in error_category::equivalent --- .../boost/system/detail/error_category.hpp | 2 ++ .../system/detail/error_category_impl.hpp | 2 +- include/boost/system/detail/error_code.hpp | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/boost/system/detail/error_category.hpp b/include/boost/system/detail/error_category.hpp index 693f75f..092fe7a 100644 --- a/include/boost/system/detail/error_category.hpp +++ b/include/boost/system/detail/error_category.hpp @@ -54,6 +54,8 @@ private: friend std::size_t hash_value( error_code const & ec ); friend BOOST_SYSTEM_CONSTEXPR bool detail::failed_impl( int ev, error_category const & cat ); + + friend class error_code; friend class error_condition; #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) diff --git a/include/boost/system/detail/error_category_impl.hpp b/include/boost/system/detail/error_category_impl.hpp index 66f2f60..7052d18 100644 --- a/include/boost/system/detail/error_category_impl.hpp +++ b/include/boost/system/detail/error_category_impl.hpp @@ -38,7 +38,7 @@ inline bool error_category::equivalent( int code, const error_condition & condit inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT { - return *this == code.category() && code.value() == condition; + return code.equals( condition, *this ); } inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT diff --git a/include/boost/system/detail/error_code.hpp b/include/boost/system/detail/error_code.hpp index 68c73c5..0984be7 100644 --- a/include/boost/system/detail/error_code.hpp +++ b/include/boost/system/detail/error_code.hpp @@ -285,6 +285,30 @@ public: // relationals: +private: + + // private equality for use in error_category::equivalent + + friend class error_category; + + BOOST_SYSTEM_CONSTEXPR bool equals( int val, error_category const& cat ) const BOOST_NOEXCEPT + { + if( lc_flags_ == 0 ) + { + return val == 0 && cat.id_ == detail::system_category_id; + } + else if( lc_flags_ == 1 ) + { + return cat.id_ == detail::interop_category_id && val == value(); + } + else + { + return val == d1_.val_ && cat == *d1_.cat_; + } + } + +public: + // the more symmetrical non-member syntax allows enum // conversions work for both rhs and lhs.