diff --git a/doc/reference.html b/doc/reference.html index 24efd4e..bf54540 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -452,7 +452,7 @@ error_code synopsis cont error_category & category() const noexcept; error_condition default_error_condition() const noexcept; string message() const; - operator unspecified-bool-type() const; + explicit operator bool() const noexcept; private: int val_; // exposition only @@ -517,20 +517,10 @@ error_code observers
string message() const;

Returns:  category().message( value()).

-

Throws: Nothing.

-
operator unspecified-bool-type() const;
+
explicit operator bool() const noexcept;
-

Returns: if value() != 0, returns a value that will evaluate -true in a boolean context; otherwise, returns a value that will -evaluate false in a boolean context. The value type returned shall -not be convertible to int.

-

Throws: nothing.

-

[Note: This conversion can be used in contexts where a bool -is expected ( e.g., an if condition ); however, implicit conversions -( e.g., to int) that can occur with bool are not -allowed, eliminating some sources of user error. One possible implementation -choice for this type is pointer-to-member. --end note ]

+

Returns: value() != 0.

Class error_condition

The class error_condition describes an object used to hold @@ -560,10 +550,10 @@ implementation specific. --end note ]

void clear() noexcept; // observers: - int value() const noexcept; - const error_category & category() const noexcept; - string message() const; - operator unspecified-bool-type () const noexcept; + int value() const noexcept; + const error_category& category() const noexcept; + string message() const; + explicit operator bool() const noexcept; private: int val_; // exposition only @@ -626,18 +616,9 @@ observers

Returns: category().message( value() ).

-
operator unspecified-bool-type () const;
+
explicit operator bool() const noexcept;
-

Returns: If value() != 0, returns a value that will - evaluate true in a boolean context; otherwise, returns a value - that will evaluate false. The return type shall not be - convertible to int.

-

Throws: Nothing.

-

 [ Note: This conversion can be used in contexts where a bool - is expected ( e.g., an if condition ); however, implicit conversions ( e.g., to - int) that can occur with bool are not allowed, - eliminating some sources of user error. One possible implementation choice for - this type is pointer to member. --end note ]

+

Returns: value() != 0.

throws object

extern error_code throws;
@@ -812,7 +793,7 @@ application program interfaces.


Revised -February 27, 2013 +February 28, 2013

© Copyright Beman Dawes, 2006, 2007, 2008, 2013

diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 3e7689c..812e779 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -270,6 +270,12 @@ namespace boost const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; } std::string message() const { return m_cat->message(value()); } +# ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS + explicit operator bool() const BOOST_SYSTEM_NOEXCEPT + { + return m_val != 0; + } +# else typedef void (*unspecified_bool_type)(); static void unspecified_bool_true() {} @@ -282,6 +288,7 @@ namespace boost { return m_val == 0; } +# endif // relationals: // the more symmetrical non-member syntax allows enum @@ -357,6 +364,12 @@ namespace boost error_condition default_error_condition() const BOOST_SYSTEM_NOEXCEPT { return m_cat->default_error_condition(value()); } std::string message() const { return m_cat->message(value()); } +# ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS + explicit operator bool() const BOOST_SYSTEM_NOEXCEPT + { + return m_val != 0; + } +# else typedef void (*unspecified_bool_type)(); static void unspecified_bool_true() {} @@ -369,6 +382,7 @@ namespace boost { return m_val == 0; } +# endif // relationals: inline friend bool operator==( const error_code & lhs, diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1ab7442..1785f55 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -25,10 +25,10 @@ project : # command line : # input files : # requirements - static + always_show_run_output static ] [ run error_code_test.cpp - : : : shared : error_code_test_shared + : : : always_show_run_output shared : error_code_test_shared ] [ run error_code_user_test.cpp : : : static diff --git a/test/error_code_test.cpp b/test/error_code_test.cpp index a9a928e..4065848 100644 --- a/test/error_code_test.cpp +++ b/test/error_code_test.cpp @@ -59,6 +59,17 @@ namespace int main( int, char ** ) { +#ifdef BOOST_NO_CXX11_NOEXCEPT + std::cout << "BOOST_NO_CXX11_NOEXCEPT is defined" << std::endl; +#else + std::cout << "BOOST_NO_CXX11_NOEXCEPT is not defined" << std::endl; +#endif +#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS + std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is defined" << std::endl; +#else + std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is not defined" << std::endl; +#endif + std::cout << "Conversion use cases...\n"; error_condition x1( errc::file_exists ); //error_code x2( errc::file_exists ); // should fail to compile diff --git a/test/system_msvc/system_dll/system_dll.vcxproj b/test/system_msvc/system_dll/system_dll.vcxproj index e4092a3..92e55e0 100644 --- a/test/system_msvc/system_dll/system_dll.vcxproj +++ b/test/system_msvc/system_dll/system_dll.vcxproj @@ -20,12 +20,14 @@ DynamicLibrary true Unicode + v110 DynamicLibrary false true Unicode + v110 diff --git a/test/system_msvc/system_error_test/system_error_test.vcxproj b/test/system_msvc/system_error_test/system_error_test.vcxproj index 0d083cb..af9a57d 100644 --- a/test/system_msvc/system_error_test/system_error_test.vcxproj +++ b/test/system_msvc/system_error_test/system_error_test.vcxproj @@ -20,12 +20,14 @@ Application true Unicode + v110 Application false true Unicode + v110