[Boost-bugs] [Boost C++ Libraries] #5357: system::error_code::operator unspecified_bool_type() should not assume 0 == success.

Subject: [Boost-bugs] [Boost C++ Libraries] #5357: system::error_code::operator unspecified_bool_type() should not assume 0 == success.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-03-23 00:37:24


#5357: system::error_code::operator unspecified_bool_type() should not assume 0 ==
success.
----------------------------------+-----------------------------------------
 Reporter: mgruenke@… | Owner: bemandawes
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: system
  Version: Boost 1.45.0 | Severity: Problem
 Keywords: |
----------------------------------+-----------------------------------------
 [The following was submitted for discussion to boost_at_[hidden] on
 2011-03-10. It received only one response, which was supportive.]

 I've found boost.system to be very useful for wrapping return codes from
 3rd party libraries (e.g. libcurl). However, one problem I've encountered
 is that error_code's operator for boolean tests assumes that an error
 value of 0 == success. While this is often true, it is not universally so
 and precludes use of boost.system for such tasks as wrapping HTTP status
 codes (several of which are merely informative and don't indicate an
 error).

 I've found it puzzling that the logic for determining whether an error
 value represents an error doesn't reside in the error_category, where it
 can be customized as needed. For instance, boolean tests could chain to a
 is_error() virtual method in the error_category, the default
 implementation of which preserves the current behavior:

 {{{#!C++
   namespace boost
   {
     namespace system
     {
       class error_category : public noncopyable
       {
       public:

         // ...

         virtual bool is_error( int ev ) const
         {
           return ev != 0;
         }

         // ...

       };


       class error_code
       {
       public:

         // ...

         operator unspecified_bool_type() const
         {
           return m_cat->is_error( m_val ) ? unspecified_bool_true : 0;
         }

         // ...

       };
     }
   }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5357>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC