Apply LWG issue 805, using a namespace to emulate scoped enums.

[SVN r46645]
This commit is contained in:
Beman Dawes
2008-06-24 14:59:10 +00:00
parent 69d2a2234c
commit 2953464e99
3 changed files with 52 additions and 50 deletions

View File

@@ -132,10 +132,10 @@ provided, so users may ignore these macros if they prefer.</p>
template< class T="" > template< class T="" >
struct is_error_condition_enum { static const bool value = false; }; struct is_error_condition_enum { static const bool value = false; };
// portable error_conditions // generic error_conditions
namespace posix_error namespace errc
{ {
enum posix_errno enum errc_t
{ {
success = 0, success = 0,
address_family_not_supported, //EAFNOSUPPORT address_family_not_supported, //EAFNOSUPPORT
@@ -218,9 +218,9 @@ provided, so users may ignore these macros if they prefer.</p>
wrong_protocol_type //EPROTOTYPE wrong_protocol_type //EPROTOTYPE
}; };
} // namespace posix_error } // namespace errc
template<> struct is_error_condition_enum<posix::posix_errno>&lt;posix_error::posix_errno&gt; template<> struct is_error_condition_enum<posix::posix_errno>&lt;errc::errc_t&gt;
{ static const bool value = true; }; { static const bool value = true; };
bool operator==( const error_code &amp; lhs, const error_code &amp; rhs ); bool operator==( const error_code &amp; lhs, const error_code &amp; rhs );
@@ -236,8 +236,8 @@ provided, so users may ignore these macros if they prefer.</p>
bool operator&lt;( const error_code &amp; lhs, const error_code &amp; rhs ); bool operator&lt;( const error_code &amp; lhs, const error_code &amp; rhs );
bool operator&lt;( const error_condition &amp; lhs, const error_condition &amp; rhs ); bool operator&lt;( const error_condition &amp; lhs, const error_condition &amp; rhs );
error_code make_error_code( posix_error::posix_errno e ); error_code make_error_code( errc::errc_t e );
error_condition make_error_condition( posix_error::posix_errno e ); error_condition make_error_condition( errc::errc_t e );
template &lt;class charT, class traits&gt; template &lt;class charT, class traits&gt;
std::basic_ostream&lt;charT,traits&gt;&amp; std::basic_ostream&lt;charT,traits&gt;&amp;
@@ -247,7 +247,7 @@ provided, so users may ignore these macros if they prefer.</p>
} }
}</pre> }</pre>
</blockquote> </blockquote>
<p>The value of each<code> posix_errno</code> constant shall be the same as the <p>The value of each<code> errc_t</code> constant shall be the same as the
value of the <code>&lt;cerrno&gt;</code> macro shown in the above synopsis.</p> value of the <code>&lt;cerrno&gt;</code> macro shown in the above synopsis.</p>
<p>Users may specialize <code>is_error_code_enum</code> and <code> <p>Users may specialize <code>is_error_code_enum</code> and <code>
is_error_condition_enum</code> templates to indicate that a type is eligible for is_error_condition_enum</code> templates to indicate that a type is eligible for
@@ -290,10 +290,10 @@ types should create a single object of each such type. <i>
}; };
const error_category &amp; get_system_category(); const error_category &amp; get_system_category();
const error_category &amp; get_posix_category(); const error_category &amp; get_generic_category();
static const error_category &amp; system_category = get_system_category(); static const error_category &amp; system_category = get_system_category();
static const error_category &amp; posix_category = get_posix_category(); static const error_category &amp; generic_category = get_generic_category();
} }
}</pre> }</pre>
</blockquote> </blockquote>
@@ -316,7 +316,7 @@ this subclause.</p>
<p><i>Returns:</i>&nbsp; <code>error_condition( ev, *this )</code>.</p> <p><i>Returns:</i>&nbsp; <code>error_condition( ev, *this )</code>.</p>
<blockquote> <blockquote>
<p>&nbsp;[<i>--Note:</i> Derived classes will typically convert <code>ev</code> <p>&nbsp;[<i>--Note:</i> Derived classes will typically convert <code>ev</code>
to some portable <code>error_category</code>, such as <code>posix_category</code>, to some portable <code>error_category</code>, such as <code>generic_category</code>,
and return it as an <code>error_condition</code> for that category. <i>--end and return it as an <code>error_condition</code> for that category. <i>--end
note</i>]</p> note</i>]</p>
</blockquote> </blockquote>
@@ -361,7 +361,7 @@ non-member functions</a></h3>
identifying errors originating from the operating system.</p> identifying errors originating from the operating system.</p>
<p><i>Throws:</i> Nothing.</p> <p><i>Throws:</i> Nothing.</p>
</blockquote> </blockquote>
<pre>const error_category &amp; get_posix_category();</pre> <pre>const error_category &amp; get_generic_category();</pre>
<blockquote> <blockquote>
<p><i>Returns:</i> A reference to a <code>error_category</code> object <p><i>Returns:</i> A reference to a <code>error_category</code> object
identifying portable error conditions.</p> identifying portable error conditions.</p>
@@ -370,7 +370,7 @@ non-member functions</a></h3>
<h3><a name="Class-error_category-predefined-objects">Class <code>error_category</code> <h3><a name="Class-error_category-predefined-objects">Class <code>error_category</code>
predefined objects</a></h3> predefined objects</a></h3>
<p>Predefined objects <code>system_category</code> <p>Predefined objects <code>system_category</code>
and <code>posix_category</code> identify operating system error codes and portable error conditions, respectively.</p> and <code>generic_category</code> identify operating system error codes and portable error conditions, respectively.</p>
<h2><a name="Class-error_code">Class <code> <h2><a name="Class-error_code">Class <code>
error_code</code></a></h2> error_code</code></a></h2>
<p>The class <code>error_code</code> describes an object used to hold error code <p>The class <code>error_code</code> describes an object used to hold error code
@@ -454,7 +454,7 @@ error_code</code> modifiers</a></h3>
</blockquote> </blockquote>
<p><code>void clear();</code></p> <p><code>void clear();</code></p>
<blockquote> <blockquote>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == posix_category</code></p> <p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == generic_category</code></p>
</blockquote> </blockquote>
<h3><a name="Class-error_code-observers">Class <code> <h3><a name="Class-error_code-observers">Class <code>
error_code</code> observers</a></h3> error_code</code> observers</a></h3>
@@ -538,7 +538,7 @@ constructors</a></h3>
<pre>error_condition(); </pre> <pre>error_condition(); </pre>
<blockquote> <blockquote>
<p><i>Effects:</i> Constructs an object of type <code>error_condition</code>.</p> <p><i>Effects:</i> Constructs an object of type <code>error_condition</code>.</p>
<p><i>Postconditions:</i> <code>val_ == 0 and cat_ == posix_category</code>.</p> <p><i>Postconditions:</i> <code>val_ == 0 and cat_ == generic_category</code>.</p>
<p><i>Throws:</i> Nothing.</p> <p><i>Throws:</i> Nothing.</p>
</blockquote> </blockquote>
<pre>error_condition( value_type val, const error_category &amp; cat );</pre> <pre>error_condition( value_type val, const error_category &amp; cat );</pre>
@@ -571,7 +571,7 @@ modifiers</a></h3>
</blockquote> </blockquote>
<p><code>void clear();</code></p> <p><code>void clear();</code></p>
<blockquote> <blockquote>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == posix_category</code></p> <p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == generic_category</code></p>
</blockquote> </blockquote>
<h3><a name="Class-error_condition-observers">Class <code>error_condition</code> <h3><a name="Class-error_condition-observers">Class <code>error_condition</code>
observers</a></h3> observers</a></h3>
@@ -651,13 +651,13 @@ bool operator!=( const error_condition &amp; condition, const error_code &amp; c
&nbsp; || (lhs.category() == rhs.category() &amp;&amp; lhs.value() &lt; rhs.value())</code>.</p> &nbsp; || (lhs.category() == rhs.category() &amp;&amp; lhs.value() &lt; rhs.value())</code>.</p>
<p><i>Throws: </i>Nothing.</p> <p><i>Throws: </i>Nothing.</p>
</blockquote> </blockquote>
<pre>error_code make_error_code( posix_error::posix_errno e );</pre> <pre>error_code make_error_code( errc::errc_t e );</pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <code>error_code( e, posix_category)</code>.</p> <p><i>Returns:</i> <code>error_code( e, generic_category)</code>.</p>
</blockquote> </blockquote>
<pre>error_condition make_error_condition( posix_error::posix_errno e );</pre> <pre>error_condition make_error_condition( errc::errc_t e );</pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <code>error_condition( e, posix_category)</code>.</p> <p><i>Returns:</i> <code>error_condition( e, generic_category)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class charT, class traits&gt; <pre>template &lt;class charT, class traits&gt;
@@ -743,7 +743,7 @@ Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p> <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
<p>Revised <p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->November 12, 2007<!--webbot bot="Timestamp" endspan i-checksum="39581" --> </font> <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->June 24, 2008<!--webbot bot="Timestamp" endspan i-checksum="14232" --> </font>
</p> </p>
</body> </body>

View File

@@ -47,11 +47,11 @@ namespace boost
template< class T > template< class T >
struct is_error_condition_enum { static const bool value = false; }; struct is_error_condition_enum { static const bool value = false; };
// portable error_conditions -------------------------------------------// // generic error_conditions --------------------------------------------//
namespace posix_error namespace errc
{ {
enum posix_errno enum errc_t
{ {
success = 0, success = 0,
address_family_not_supported = EAFNOSUPPORT, address_family_not_supported = EAFNOSUPPORT,
@@ -134,13 +134,14 @@ namespace boost
wrong_protocol_type = EPROTOTYPE wrong_protocol_type = EPROTOTYPE
}; };
} // namespace posix_error } // namespace errc
# ifndef BOOST_SYSTEM_NO_DEPRECATED # ifndef BOOST_SYSTEM_NO_DEPRECATED
namespace posix = posix_error; namespace posix = errc;
namespace posix_error = errc;
# endif # endif
template<> struct is_error_condition_enum<posix_error::posix_errno> template<> struct is_error_condition_enum<errc::errc_t>
{ static const bool value = true; }; { static const bool value = true; };
@@ -199,15 +200,16 @@ namespace boost
// predefined error categories -----------------------------------------// // predefined error categories -----------------------------------------//
BOOST_SYSTEM_DECL const error_category & get_system_category(); BOOST_SYSTEM_DECL const error_category & get_system_category();
BOOST_SYSTEM_DECL const error_category & get_posix_category(); BOOST_SYSTEM_DECL const error_category & get_generic_category();
static const error_category & system_category = get_system_category(); static const error_category & system_category = get_system_category();
static const error_category & posix_category = get_posix_category(); static const error_category & generic_category = get_generic_category();
# ifndef BOOST_SYSTEM_NO_DEPRECATED # ifndef BOOST_SYSTEM_NO_DEPRECATED
// deprecated synonyms // deprecated synonyms
static const error_category & errno_ecat = get_posix_category(); static const error_category & posix_category = get_generic_category();
static const error_category & native_ecat = get_system_category(); static const error_category & errno_ecat = get_generic_category();
static const error_category & native_ecat = get_system_category();
# endif # endif
// class error_condition -----------------------------------------------// // class error_condition -----------------------------------------------//
@@ -219,7 +221,7 @@ namespace boost
public: public:
// constructors: // constructors:
error_condition() : m_val(0), m_cat(&get_posix_category()) {} error_condition() : m_val(0), m_cat(&get_generic_category()) {}
error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {}
template <class ConditionEnum> template <class ConditionEnum>
@@ -248,7 +250,7 @@ namespace boost
void clear() void clear()
{ {
m_val = 0; m_val = 0;
m_cat = &get_posix_category(); m_cat = &get_generic_category();
} }
// observers: // observers:
@@ -436,17 +438,17 @@ namespace boost
+ reinterpret_cast<std::size_t>(&ec.category()); + reinterpret_cast<std::size_t>(&ec.category());
} }
// make_* functions for posix_error::posix_errno -----------------------------// // make_* functions for errc::errc_t -----------------------------//
namespace posix_error namespace errc
{ {
// explicit conversion: // explicit conversion:
inline error_code make_error_code( posix_errno e ) inline error_code make_error_code( errc_t e )
{ return error_code( e, get_posix_category() ); } { return error_code( e, get_generic_category() ); }
// implicit conversion: // implicit conversion:
inline error_condition make_error_condition( posix_errno e ) inline error_condition make_error_condition( errc_t e )
{ return error_condition( e, get_posix_category() ); } { return error_condition( e, get_generic_category() ); }
} }
// error_category default implementation -------------------------------// // error_category default implementation -------------------------------//

View File

@@ -38,12 +38,12 @@ using namespace boost::system::posix_error;
namespace namespace
{ {
// standard error categories -------------------------------------------// // standard error categories ---------------------------------------------//
class posix_error_category : public error_category class generic_error_category : public error_category
{ {
public: public:
posix_error_category(){} generic_error_category(){}
const char * name() const; const char * name() const;
std::string message( int ev ) const; std::string message( int ev ) const;
}; };
@@ -57,14 +57,14 @@ namespace
error_condition default_error_condition( int ev ) const; error_condition default_error_condition( int ev ) const;
}; };
// posix_error_category implementation ---------------------------------// // generic_error_category implementation ---------------------------------//
const char * posix_error_category::name() const const char * generic_error_category::name() const
{ {
return "POSIX"; return "GENERIC";
} }
std::string posix_error_category::message( int ev ) const std::string generic_error_category::message( int ev ) const
{ {
// strerror_r is preferred because it is always thread safe, // strerror_r is preferred because it is always thread safe,
// however, we fallback to strerror in certain cases because: // however, we fallback to strerror in certain cases because:
@@ -318,7 +318,7 @@ namespace
std::string system_error_category::message( int ev ) const std::string system_error_category::message( int ev ) const
{ {
return posix_category.message( ev ); return generic_category.message( ev );
} }
# else # else
// TODO: // TODO:
@@ -402,10 +402,10 @@ namespace boost
return system_category_const; return system_category_const;
} }
BOOST_SYSTEM_DECL const error_category & get_posix_category() BOOST_SYSTEM_DECL const error_category & get_generic_category()
{ {
static const posix_error_category posix_category_const; static const generic_error_category generic_category_const;
return posix_category_const; return generic_category_const;
} }
} // namespace system } // namespace system