diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index f40a99e..472a55b 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -2,6 +2,7 @@ // Copyright Beman Dawes 2006, 2007 // Copyright Christoper Kohlhoff 2007 +// Copyright Peter Dimov 2017, 2018 // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -541,6 +542,15 @@ inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; } std::string message() const { return m_cat->message(value()); } +#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) + + explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error + { + return m_val != 0; + } + +#else + typedef void (*unspecified_bool_type)(); static void unspecified_bool_true() {} @@ -554,6 +564,8 @@ inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT return m_val == 0; } +#endif + // relationals: // the more symmetrical non-member syntax allows enum // conversions work for both rhs and lhs. @@ -640,6 +652,15 @@ inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT { return m_cat->default_error_condition(value()); } std::string message() const { return m_cat->message(value()); } +#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) + + explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error + { + return m_val != 0; + } + +#else + typedef void (*unspecified_bool_type)(); static void unspecified_bool_true() {} @@ -653,6 +674,8 @@ inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT return m_val == 0; } +#endif + // relationals: BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT diff --git a/test/quick.cpp b/test/quick.cpp index 882b834..ca66983 100644 --- a/test/quick.cpp +++ b/test/quick.cpp @@ -30,7 +30,7 @@ int main() BOOST_TEST( bt.equivalent( ev, bn ) ); - BOOST_TEST_EQ( bc, bn ); + BOOST_TEST( bc == bn ); return boost::report_errors(); }