From a5deb196f343f807ec1543efae3ad0c41d2c26e9 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Fri, 17 Feb 2017 15:49:53 +0300 Subject: [PATCH] Merge to master: Use C++11 explicit conversion operator if available This change brings leftover parts of commit 08ea984237321c015a03705612eca910a96643f8 to master, in order to synchronize it with develop. --- doc/reference.html | 39 ++++++++++--------------------------- include/boost/system/error_code.hpp | 14 +++++++++++++ test/Jamfile.v2 | 4 ++-- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index 5671435..d2efbb2 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -458,7 +458,7 @@ 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 @@ -523,20 +523,10 @@
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 @@ -566,10 +556,10 @@ 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 @@ -632,18 +622,9 @@

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

-
operator unspecified-bool-type () const;
-
-

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 ]

+
explicit operator bool() const noexcept;
+
+

Returns: value() != 0.

throws object

extern error_code throws;
diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index b6ff6e4..6ec444f 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 024cb88..c6008fc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -26,10 +26,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