Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2007-08-02 11:10:43


Author: bemandawes
Date: 2007-08-02 11:10:43 EDT (Thu, 02 Aug 2007)
New Revision: 38398
URL: http://svn.boost.org/trac/boost/changeset/38398

Log:
Add generic_error_code, equal, equivalent, and redefine operator== in terms of those
Text files modified:
   branches/c++0x/boost/boost/system/error_code.hpp | 17 +++++++++++++++--
   1 files changed, 15 insertions(+), 2 deletions(-)

Modified: branches/c++0x/boost/boost/system/error_code.hpp
==============================================================================
--- branches/c++0x/boost/boost/system/error_code.hpp (original)
+++ branches/c++0x/boost/boost/system/error_code.hpp 2007-08-02 11:10:43 EDT (Thu, 02 Aug 2007)
@@ -30,6 +30,7 @@
   {
 
     class error_code;
+ bool equivalent( const error_code & lhs, const error_code & rhs );
 
     namespace posix
     {
@@ -129,6 +130,7 @@
       virtual ~error_category(){}
       virtual const std::string & name() const = 0;
       virtual posix::posix_errno posix( int ev) const = 0;
+ virtual error_code generic_error_code( int ev) const = 0;
       virtual std::string message( int ev ) const = 0;
 
       bool operator==(const error_category & rhs) const { return this == &rhs; }
@@ -187,6 +189,7 @@
       int value() const { return m_val; }
       const error_category & category() const { return *m_cat; }
       posix::posix_errno posix() const { return m_cat->posix(value()); }
+ error_code generic_error_code() const { return m_cat->generic_error_code(value()); }
       std::string message() const { return m_cat->message(value()); }
 
       typedef void (*unspecified_bool_type)();
@@ -206,8 +209,7 @@
       bool operator==( const error_code & rhs ) const
       {
         if ( category() == rhs.category() ) return value() == rhs.value();
- return (category() == posix_category || rhs.category() == posix_category)
- && posix() == rhs.posix();
+ return equivalent( *this, rhs );
       }
 
       bool operator!=( const error_code & rhs ) const
@@ -223,6 +225,17 @@
 
     // non-member functions ------------------------------------------------//
 
+ // the more symmetrical non-member syntax is preferred
+ inline bool equal( const error_code & lhs, const error_code & rhs )
+ {
+ return lhs.category() == rhs.category() && lhs.value() == rhs.value();
+ }
+
+ inline bool equivalent( const error_code & lhs, const error_code & rhs )
+ {
+ return equal( lhs.generic_error_code(), rhs.generic_error_code() );
+ }
+
     // posix::posix_errno make_error_code:
     inline error_code make_error_code( posix::posix_errno e )
       { return error_code( e, posix_category ); }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk