From 87c427b5dfdcf8c84a81d07e454bf78b431489ee Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 22 Jun 2017 19:27:55 +0300 Subject: [PATCH] Rework the equivalence logic in terms of the corresponding downstream `equivalent` --- include/boost/system/error_code.hpp | 37 ++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index dd585d7..5d98301 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -618,45 +618,60 @@ namespace boost inline bool error_category::std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT { - if( default_error_condition( code ) == condition ) + if( condition.category() == *this ) { - return true; + boost::system::error_condition bn( condition.value(), *pc_ ); + return pc_->equivalent( code, bn ); } else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() ) { - boost::system::error_code bc( code, *pc_ ); boost::system::error_condition bn( condition.value(), boost::system::generic_category() ); - return bc == bn; + return pc_->equivalent( code, bn ); } #ifndef BOOST_NO_RTTI else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) ) { - boost::system::error_code bc( code, *pc_ ); boost::system::error_condition bn( condition.value(), *pc2->pc_ ); - - return bc == bn; + return pc_->equivalent( code, bn ); } #endif else { - return false; + return default_error_condition( code ) == condition; } } inline bool error_category::std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT { - if( *this == code.category() && code.value() == condition ) + if( code.category() == *this ) { - return true; + boost::system::error_code bc( code.value(), *pc_ ); + return pc_->equivalent( bc, condition ); } + else if( code.category() == std::generic_category() + || code.category() == boost::system::generic_category() ) + { + boost::system::error_code bc( code.value(), + boost::system::generic_category() ); + + return pc_->equivalent( bc, condition ); + } +#ifndef BOOST_NO_RTTI + else if( std_category const* pc2 = dynamic_cast< std_category const* >( + &code.category() ) ) + { + boost::system::error_code bc( code.value(), *pc2->pc_ ); + return pc_->equivalent( bc, condition ); + } +#endif else if( *pc_ == boost::system::generic_category() ) { - return code == std::error_condition( condition, std::generic_category() ); + return std::generic_category().equivalent( code, condition ); } else {