diff --git a/include/boost/system/detail/error_condition.hpp b/include/boost/system/detail/error_condition.hpp index fb9f844..6b38376 100644 --- a/include/boost/system/detail/error_condition.hpp +++ b/include/boost/system/detail/error_condition.hpp @@ -32,7 +32,6 @@ class error_condition private: int val_; - bool failed_; error_category const * cat_; public: @@ -40,12 +39,12 @@ public: // constructors: BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_NOEXCEPT: - val_( 0 ), failed_( false ), cat_( &generic_category() ) + val_( 0 ), cat_( &generic_category() ) { } BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_NOEXCEPT: - val_( val ), failed_( detail::failed_impl( val, cat ) ), cat_( &cat ) + val_( val ), cat_( &cat ) { } @@ -60,7 +59,6 @@ public: BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT { val_ = val; - failed_ = detail::failed_impl( val, cat ); cat_ = &cat; } @@ -75,7 +73,6 @@ public: BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT { val_ = 0; - failed_ = false; cat_ = &generic_category(); } @@ -96,21 +93,21 @@ public: return cat_->message( value() ); } - char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT + BOOST_SYSTEM_DEPRECATED("this function is slated for removal") char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT { return cat_->message( value(), buffer, len ); } - BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT + BOOST_SYSTEM_DEPRECATED("this function is slated for removal") BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT { - return failed_; + return detail::failed_impl( val_, *cat_ ); } #if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error { - return failed_; + return val_ != 0; } #else @@ -120,12 +117,12 @@ public: BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error { - return failed_? unspecified_bool_true: 0; + return val_ != 0? unspecified_bool_true: 0; } BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error { - return !failed_; + return val_ == 0; } #endif diff --git a/test/failed_test.cpp b/test/failed_test.cpp index 118d35f..9f00b34 100644 --- a/test/failed_test.cpp +++ b/test/failed_test.cpp @@ -120,18 +120,30 @@ template void test() ec.assign( 0, generic_category() ); TEST_NOT_FAILED( ec ); } +} - { - Ec ec( 0, http_category() ); - TEST_FAILED( ec ); +template void test2() +{ + Ec ec( 0, http_category() ); + TEST_FAILED( ec ); - ec.assign( 200, http_category() ); - TEST_NOT_FAILED( ec ); + ec.assign( 200, http_category() ); + TEST_NOT_FAILED( ec ); - ec = Ec( 404, http_category() ); - TEST_FAILED( ec ); - } + ec = Ec( 404, http_category() ); + TEST_FAILED( ec ); +} +template void test3() +{ + Ec ec( 0, http_category() ); + BOOST_TEST( ec.failed() ); + + ec.assign( 200, http_category() ); + BOOST_TEST( !ec.failed() ); + + ec = Ec( 404, http_category() ); + BOOST_TEST( ec.failed() ); } int main() @@ -147,7 +159,9 @@ int main() BOOST_TEST( http_category().failed( 404 ) ); test(); + test2(); test(); + test3(); { error_condition ec( errc::success );