Move code == condition comparisons into error_code, unwrap std::error_code when needed

This commit is contained in:
Peter Dimov
2021-06-14 04:06:24 +03:00
parent 42a257e17c
commit 9fdfa6c645
2 changed files with 42 additions and 33 deletions

View File

@ -300,6 +300,48 @@ public:
return !( lhs == rhs );
}
inline friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline friend bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline friend bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline friend bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
inline friend bool operator==( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT

View File

@ -17,38 +17,5 @@
#include <boost/system/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/system/detail/throws.hpp>
#include <boost/config.hpp>
namespace boost
{
namespace system
{
// non-member functions of error_code and error_condition
inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
inline bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
} // namespace system
} // namespace boost
#endif // BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED