|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83210 - in trunk: boost/system libs/system/doc libs/system/test libs/system/test/system_msvc/system_dll libs/system/test/system_msvc/system_error_test
From: bdawes_at_[hidden]
Date: 2013-02-28 15:55:10
Author: bemandawes
Date: 2013-02-28 15:55:07 EST (Thu, 28 Feb 2013)
New Revision: 83210
URL: http://svn.boost.org/trac/boost/changeset/83210
Log:
Use C++11 explicit conversion operator if available
Text files modified:
trunk/boost/system/error_code.hpp | 14 ++++++++++++++
trunk/libs/system/doc/reference.html | 39 ++++++++++-----------------------------
trunk/libs/system/test/Jamfile.v2 | 4 ++--
trunk/libs/system/test/error_code_test.cpp | 11 +++++++++++
trunk/libs/system/test/system_msvc/system_dll/system_dll.vcxproj | 2 ++
trunk/libs/system/test/system_msvc/system_error_test/system_error_test.vcxproj | 2 ++
6 files changed, 41 insertions(+), 31 deletions(-)
Modified: trunk/boost/system/error_code.hpp
==============================================================================
--- trunk/boost/system/error_code.hpp (original)
+++ trunk/boost/system/error_code.hpp 2013-02-28 15:55:07 EST (Thu, 28 Feb 2013)
@@ -270,6 +270,12 @@
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 @@
{
return m_val == 0;
}
+# endif
// relationals:
// the more symmetrical non-member syntax allows enum
@@ -357,6 +364,12 @@
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 @@
{
return m_val == 0;
}
+# endif
// relationals:
inline friend bool operator==( const error_code & lhs,
Modified: trunk/libs/system/doc/reference.html
==============================================================================
--- trunk/libs/system/doc/reference.html (original)
+++ trunk/libs/system/doc/reference.html 2013-02-28 15:55:07 EST (Thu, 28 Feb 2013)
@@ -452,7 +452,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_; // <i>exposition only</i>
@@ -517,20 +517,10 @@
<pre><code>string message() const;</code></pre>
<blockquote>
<p><i>Returns:</i> <code>category().message( value())</code>.</p>
- <p><i>Throws:</i> Nothing.</p>
</blockquote>
-<pre>operator unspecified-bool-type() const;</pre>
+<pre>explicit operator bool() const noexcept;</pre>
<blockquote>
-<p><i>Returns:</i> if <code>value() != 0</code>, returns a value that will evaluate
-<code>true</code> in a boolean context; otherwise, returns a value that will
-evaluate <code>false</code> in a boolean context. The value type returned shall
-not be convertible to <code>int</code>.</p>
-<p><i>Throws:</i> nothing.</p>
-<p><i>[Note: </i>This conversion can be used in contexts where a <code>bool</code>
-is expected ( e.g., an <code>if</code> condition ); however, implicit conversions
-( e.g., to <code>int</code>) that can occur with <code>bool</code> are not
-allowed, eliminating some sources of user error. One possible implementation
-choice for this type is pointer-to-member. <i>--end note ]</i></p>
+<p><i>Returns:</i> <code>value() != 0</code>.</p>
</blockquote>
<h2><a name="Class-error_condition">Class <code>error_condition</code></a></h2>
<p>The class <code>error_condition</code> describes an object used to hold
@@ -560,10 +550,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_; // <i>exposition only</i>
@@ -626,18 +616,9 @@
<blockquote>
<p><i>Returns:</i> <code>category().message( value() )</code>.</p>
</blockquote>
-<pre>operator unspecified-bool-type () const;</pre>
+<pre>explicit operator bool() const noexcept;</pre>
<blockquote>
- <p><i>Returns: </i>If <code>value() != 0</code>, returns a value that will
- evaluate <code>true</code> in a boolean context; otherwise, returns a value
- that will evaluate <code>false</code>. The return type shall not be
- convertible to <code>int</code>. </p>
- <p><i>Throws:</i> Nothing.</p>
- <p><i> [ Note:</i> This conversion can be used in contexts where a <code>bool</code>
- is expected ( e.g., an if condition ); however, implicit conversions ( e.g., to
- <code>int</code>) that can occur with <code>bool</code> are not allowed,
- eliminating some sources of user error. One possible implementation choice for
- this type is pointer to member. <i>--end note</i> <i>]</i></p>
+ <p><i>Returns: </i> <code>value() != 0</code>. </p>
</blockquote>
<h2><a name="throws-object"><code>throws</code> object</a></h2>
<pre>extern error_code throws;</pre>
@@ -812,7 +793,7 @@
<hr>
<p>Revised
-<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->February 27, 2013<!--webbot bot="Timestamp" endspan i-checksum="41547" --> </font>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->February 28, 2013<!--webbot bot="Timestamp" endspan i-checksum="41551" --> </font>
</p>
<p>© Copyright Beman Dawes, 2006, 2007, 2008, 2013</p>
Modified: trunk/libs/system/test/Jamfile.v2
==============================================================================
--- trunk/libs/system/test/Jamfile.v2 (original)
+++ trunk/libs/system/test/Jamfile.v2 2013-02-28 15:55:07 EST (Thu, 28 Feb 2013)
@@ -25,10 +25,10 @@
: # command line
: # input files
: # requirements
- <link>static
+ <test-info>always_show_run_output <link>static
]
[ run error_code_test.cpp
- : : : <link>shared : error_code_test_shared
+ : : : <test-info>always_show_run_output <link>shared : error_code_test_shared
]
[ run error_code_user_test.cpp
: : : <link>static
Modified: trunk/libs/system/test/error_code_test.cpp
==============================================================================
--- trunk/libs/system/test/error_code_test.cpp (original)
+++ trunk/libs/system/test/error_code_test.cpp 2013-02-28 15:55:07 EST (Thu, 28 Feb 2013)
@@ -59,6 +59,17 @@
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
Modified: trunk/libs/system/test/system_msvc/system_dll/system_dll.vcxproj
==============================================================================
--- trunk/libs/system/test/system_msvc/system_dll/system_dll.vcxproj (original)
+++ trunk/libs/system/test/system_msvc/system_dll/system_dll.vcxproj 2013-02-28 15:55:07 EST (Thu, 28 Feb 2013)
@@ -20,12 +20,14 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Modified: trunk/libs/system/test/system_msvc/system_error_test/system_error_test.vcxproj
==============================================================================
--- trunk/libs/system/test/system_msvc/system_error_test/system_error_test.vcxproj (original)
+++ trunk/libs/system/test/system_msvc/system_error_test/system_error_test.vcxproj 2013-02-28 15:55:07 EST (Thu, 28 Feb 2013)
@@ -20,12 +20,14 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk