Rework error_condition::op== to not require the generic_category() instance

This commit is contained in:
Peter Dimov
2021-09-19 04:49:35 +03:00
parent 361834e49c
commit c8c5ad1ce5
2 changed files with 24 additions and 1 deletions

View File

@ -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:

View File

@ -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