forked from boostorg/system
Use C++11 explicit conversion operator if available
[SVN r83210]
This commit is contained in:
@ -452,7 +452,7 @@ error_code</code> synopsis</a></h3>
|
|||||||
cont error_category & category() const noexcept;
|
cont error_category & category() const noexcept;
|
||||||
error_condition default_error_condition() const noexcept;
|
error_condition default_error_condition() const noexcept;
|
||||||
string message() const;
|
string message() const;
|
||||||
operator unspecified-bool-type() const;
|
explicit operator bool() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int val_; // <i>exposition only</i>
|
int val_; // <i>exposition only</i>
|
||||||
@ -517,20 +517,10 @@ error_code</code> observers</a></h3>
|
|||||||
<pre><code>string message() const;</code></pre>
|
<pre><code>string message() const;</code></pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p><i>Returns:</i> <code>category().message( value())</code>.</p>
|
<p><i>Returns:</i> <code>category().message( value())</code>.</p>
|
||||||
<p><i>Throws:</i> Nothing.</p>
|
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<pre>operator unspecified-bool-type() const;</pre>
|
<pre>explicit operator bool() const noexcept;</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p><i>Returns:</i> if <code>value() != 0</code>, returns a value that will evaluate
|
<p><i>Returns:</i> <code>value() != 0</code>.</p>
|
||||||
<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>
|
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<h2><a name="Class-error_condition">Class <code>error_condition</code></a></h2>
|
<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
|
<p>The class <code>error_condition</code> describes an object used to hold
|
||||||
@ -560,10 +550,10 @@ implementation specific. <i>--end note ]</i></p>
|
|||||||
void clear() noexcept;
|
void clear() noexcept;
|
||||||
|
|
||||||
// observers:
|
// observers:
|
||||||
int value() const noexcept;
|
int value() const noexcept;
|
||||||
const error_category & category() const noexcept;
|
const error_category& category() const noexcept;
|
||||||
string message() const;
|
string message() const;
|
||||||
operator unspecified-bool-type () const noexcept;
|
explicit operator bool() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int val_; // <i>exposition only</i>
|
int val_; // <i>exposition only</i>
|
||||||
@ -626,18 +616,9 @@ observers</a></h3>
|
|||||||
<blockquote>
|
<blockquote>
|
||||||
<p><i>Returns:</i> <code>category().message( value() )</code>.</p>
|
<p><i>Returns:</i> <code>category().message( value() )</code>.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<pre>operator unspecified-bool-type () const;</pre>
|
<pre>explicit operator bool() const noexcept;</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p><i>Returns: </i>If <code>value() != 0</code>, returns a value that will
|
<p><i>Returns: </i> <code>value() != 0</code>. </p>
|
||||||
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>
|
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<h2><a name="throws-object"><code>throws</code> object</a></h2>
|
<h2><a name="throws-object"><code>throws</code> object</a></h2>
|
||||||
<pre>extern error_code throws;</pre>
|
<pre>extern error_code throws;</pre>
|
||||||
@ -812,7 +793,7 @@ application program interfaces.</p>
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>Revised
|
<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>
|
||||||
|
|
||||||
<p><EFBFBD> Copyright Beman Dawes, 2006, 2007, 2008, 2013</p>
|
<p><EFBFBD> Copyright Beman Dawes, 2006, 2007, 2008, 2013</p>
|
||||||
|
@ -270,6 +270,12 @@ namespace boost
|
|||||||
const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
|
const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
|
||||||
std::string message() const { return m_cat->message(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)();
|
typedef void (*unspecified_bool_type)();
|
||||||
static void unspecified_bool_true() {}
|
static void unspecified_bool_true() {}
|
||||||
|
|
||||||
@ -282,6 +288,7 @@ namespace boost
|
|||||||
{
|
{
|
||||||
return m_val == 0;
|
return m_val == 0;
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
// relationals:
|
// relationals:
|
||||||
// the more symmetrical non-member syntax allows enum
|
// 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()); }
|
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()); }
|
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)();
|
typedef void (*unspecified_bool_type)();
|
||||||
static void unspecified_bool_true() {}
|
static void unspecified_bool_true() {}
|
||||||
|
|
||||||
@ -369,6 +382,7 @@ namespace boost
|
|||||||
{
|
{
|
||||||
return m_val == 0;
|
return m_val == 0;
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
// relationals:
|
// relationals:
|
||||||
inline friend bool operator==( const error_code & lhs,
|
inline friend bool operator==( const error_code & lhs,
|
||||||
|
@ -25,10 +25,10 @@ project
|
|||||||
: # command line
|
: # command line
|
||||||
: # input files
|
: # input files
|
||||||
: # requirements
|
: # requirements
|
||||||
<link>static
|
<test-info>always_show_run_output <link>static
|
||||||
]
|
]
|
||||||
[ run error_code_test.cpp
|
[ 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
|
[ run error_code_user_test.cpp
|
||||||
: : : <link>static
|
: : : <link>static
|
||||||
|
@ -59,6 +59,17 @@ namespace
|
|||||||
int main( int, char ** )
|
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";
|
std::cout << "Conversion use cases...\n";
|
||||||
error_condition x1( errc::file_exists );
|
error_condition x1( errc::file_exists );
|
||||||
//error_code x2( errc::file_exists ); // should fail to compile
|
//error_code x2( errc::file_exists ); // should fail to compile
|
||||||
|
@ -20,12 +20,14 @@
|
|||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v110</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v110</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
@ -20,12 +20,14 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v110</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v110</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
Reference in New Issue
Block a user