From c8c5ad1ce5f94097a98e69ba8d9e9e4958daf1ec Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 19 Sep 2021 04:49:35 +0300 Subject: [PATCH] Rework error_condition::op== to not require the generic_category() instance --- .../boost/system/detail/error_category.hpp | 1 + .../boost/system/detail/error_condition.hpp | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/boost/system/detail/error_category.hpp b/include/boost/system/detail/error_category.hpp index b91c193..693f75f 100644 --- a/include/boost/system/detail/error_category.hpp +++ b/include/boost/system/detail/error_category.hpp @@ -54,6 +54,7 @@ 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_condition; #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) public: diff --git a/include/boost/system/detail/error_condition.hpp b/include/boost/system/detail/error_condition.hpp index 4ac9c70..c52d495 100644 --- a/include/boost/system/detail/error_condition.hpp +++ b/include/boost/system/detail/error_condition.hpp @@ -47,6 +47,13 @@ private: int val_; error_category const * cat_; +private: + + boost::ulong_long_type cat_id() const BOOST_NOEXCEPT + { + return cat_? cat_->id_: detail::generic_category_id; + } + public: // constructors: @@ -180,7 +187,22 @@ public: BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT { - return lhs.val_ == rhs.val_ && lhs.category() == rhs.category(); + if( lhs.val_ != rhs.val_ ) + { + return false; + } + else if( lhs.cat_ == 0 ) + { + return rhs.cat_id() == detail::generic_category_id; + } + else if( rhs.cat_ == 0 ) + { + return lhs.cat_id() == detail::generic_category_id; + } + else + { + return *lhs.cat_ == *rhs.cat_; + } } BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT