Decompose Reversible into EndianReversible and EndianReversibleInplace.

This commit is contained in:
Beman
2014-12-11 11:41:44 -05:00
parent 6c173766e3
commit 971ba888d6
3 changed files with 191 additions and 171 deletions

View File

@@ -1,4 +1,4 @@
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40"> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">
<head> <head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
@@ -45,7 +45,7 @@
<a href="#Reference">Reference</a><br> <a href="#Reference">Reference</a><br>
&nbsp;&nbsp;&nbsp; <a href="#Synopsis">Synopsis</a><br> &nbsp;&nbsp;&nbsp; <a href="#Synopsis">Synopsis</a><br>
&nbsp;&nbsp;&nbsp; <a href="#Requirements">Requirements</a><br> &nbsp;&nbsp;&nbsp; <a href="#Requirements">Requirements</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code><a href="#Reversible">Reversible</a></code><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code><a href="#EndianReversible">EndianReversible</a></code><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#Customization-points">Customization for &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#Customization-points">Customization for
UDTs</a><br> UDTs</a><br>
<a href="#Functions">Functions</a><br> <a href="#Functions">Functions</a><br>
@@ -98,6 +98,7 @@ namespace endian
native = <b><i>implementation-defined-as-big-or-little native = <b><i>implementation-defined-as-big-or-little
</i></b>}; </i></b>};
<span style="background-color: #FFFF00">TODO</span><span style="background-color: #FFFF00">: Add overloads for char, </span><span style="background-color: #FFFF00">wchar_t</span><span style="background-color: #FFFF00">, char16_t, char32_t</span>
int8_t <a href="#endian_reverse">endian_reverse</a>(int8_t x) noexcept; int8_t <a href="#endian_reverse">endian_reverse</a>(int8_t x) noexcept;
int16_t <a href="#endian_reverse">endian_reverse</a>(int16_t x) noexcept; int16_t <a href="#endian_reverse">endian_reverse</a>(int16_t x) noexcept;
int32_t <a href="#endian_reverse">endian_reverse</a>(int32_t x) noexcept; int32_t <a href="#endian_reverse">endian_reverse</a>(int32_t x) noexcept;
@@ -109,35 +110,35 @@ namespace endian
float <a href="#endian_reverse">endian_reverse</a>(float x) noexcept; float <a href="#endian_reverse">endian_reverse</a>(float x) noexcept;
double <a href="#endian_reverse">endian_reverse</a>(double x) noexcept; double <a href="#endian_reverse">endian_reverse</a>(double x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversible&gt;
Reversible big_to_native(Reversible x) noexcept; EndianReversible big_to_native(EndianReversible x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversible&gt;
Reversible native_to_big(Reversible x) noexcept; EndianReversible native_to_big(EndianReversible x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversible&gt;
Reversible little_to_native(Reversible x) noexcept; EndianReversible little_to_native(EndianReversible x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversible&gt;
Reversible native_to_little(Reversible x) noexcept; EndianReversible native_to_little(EndianReversible x) noexcept;
template &lt;order O1, order O2, class Reversible&gt; template &lt;order O1, order O2, class EndianReversible&gt;
Reversible conditional_reverse(Reversible x) noexcept; EndianReversible conditional_reverse(EndianReversible x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversible&gt;
Reversible conditional_reverse(Reversible x, EndianReversible conditional_reverse(EndianReversible x,
order order1, order order2) noexcept; order order1, order order2) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversible&gt;
void endian_reverse_inplace(Reversible&amp; x) noexcept; void endian_reverse_inplace(EndianReversible&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversibleInplace&gt;
void big_to_native_inplace(Reversible&amp; x) noexcept; void big_to_native_inplace(EndianReversibleInplace&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversibleInplace&gt;
void native_to_big_inplace(Reversible&amp; x) noexcept; void native_to_big_inplace(EndianReversibleInplace&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversibleInplace&gt;
void little_to_native_inplace(Reversible&amp; x) noexcept; void little_to_native_inplace(EndianReversibleInplace&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversibleInplace&gt;
void native_to_little_inplace(Reversible&amp; x) noexcept; void native_to_little_inplace(EndianReversibleInplace&amp; x) noexcept;
template &lt;order O1, order O2, class Reversible&gt; template &lt;order O1, order O2, class EndianReversibleInplace&gt;
void conditional_reverse_inplace(Reversible&amp; x) noexcept; void conditional_reverse_inplace(EndianReversibleInplace&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class EndianReversibleInplace&gt;
void conditional_reverse_inplace(Reversible&amp; x, void conditional_reverse_inplace(EndianReversibleInplace&amp; x,
order order1, order order2) noexcept; order order1, order order2) noexcept;
} // namespace endian } // namespace endian
@@ -146,77 +147,91 @@ namespace endian
constant <code>native</code> as constant <code>native</code> as
<code>big</code> on big endian platforms and <code>little</code> on little <code>big</code> on big endian platforms and <code>little</code> on little
endian platforms.</p> endian platforms.</p>
<h3 dir="ltr"><a name="Definitions">Definitions</a></h3>
<p dir="ltr">The standard integral types (C++std 3.9.1) except <code>bool</code>,
and the floating point types <code>float</code> and <code>double</code> are
collectively called the <i>endian types</i>.</p>
<h3><a name="Requirements">Requirements</a></h3> <h3><a name="Requirements">Requirements</a></h3>
<h4>Template argument <code><a name="Reversible">Reversible</a></code> requirements</h4> <h4><a name="Template-argument-requirements">Template argument requirements</a></h4>
<p>This subsection describes names that are used to specify constraints on <p dir="ltr">The template definitions in the <code>boost/endian/conversion.hpp</code>
template arguments.</p> header refer to various named requirements whose details are set out in the
<p>User-defined types may be used in the function templates in this header only tables in this subsection. In these tables, <code>T</code> is an object or
if they meet these requirements.</p> reference type to be supplied by a C++ program instantiating a template; <code>x</code>
<p><code>Reversible</code> is an object type to be supplied by a C++ program is a value of type (possibly <code>const</code>) <code>T</code>; <code>mlx</code> is a
instantiating a template.</p> modifiable lvalue of type <code>T</code>.</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111"> <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr> <tr>
<td width="160"><b>Expression</b></td> <td colspan="3" align="center"><b><code><a name="EndianReversible">EndianReversible</a></code></b>
<td width="160"><b>Meaning of x</b></td> requirements (in addition to <b><code>CopyConstructible</code></b>)</td>
<td width="347"><b>Requirements</b></td>
</tr> </tr>
<tr> <tr>
<td valign="top"> <td><b>Expression</b></td>
<p><code>endian_reverse(x)</code></td> <td><b>Return<br>
<td valign="top"> type</b></td>
<code>x</code> is a value of a possibly <code>const</code> type convertible <td><b>Requirements</b></td>
to <code>Reversible</code>.</td>
<td>
<p>Returns the value of <code>x</code> with the
order of its constituent bytes reversed.</td>
</tr> </tr>
<tr> <tr>
<td valign="top"> <td valign="top"><code>endian_reverse(x)</code></td>
<code>endian_reverse_inplace(x)</code></td> <td align="center" valign="top"><code>T</code></td>
<td valign="top"> <td> <code>T</code> is an endian type or a class type.<p>If <code>T</code> is
<code>x</code> is a an endian type, returns the value of <code>x</code> with the order of bytes
modifiable lvalue of type <code>Reversible</code>.</td> reversed.</p>
<td> <p>If <code>T</code> is an class type, the function:</p>
The order of the constituent bytes of <code>x</code> are <ul>
reversed.</td> <li>Returns the value of <code>x</code>
with the order of bytes reversed for all data members of types or arrays of
types that meet the <code>EndianReversible</code> requirements, and;</li>
<li>Is a non-member function in the same namespace as <code>T</code> that
can be found by argument dependent lookup (ADL). </li>
</ul>
</td>
</tr>
</table>
<p>&nbsp;</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td colspan="2" align="center"><b><code><a name="EndianReversibleInplace">EndianReversibleInplace</a></code></b>
requirements (in addition to <b><code>CopyConstructible</code></b>)</td>
</tr>
<tr>
<td><b>Expression</b></td>
<td><b>Requirements</b></td>
</tr>
<tr>
<td valign="top"><code>endian_reverse_inplace(mlx)</code></td>
<td> <code>T</code> is an endian type or a class type.<p>If <code>T</code> is
an endian type, reverses the order of bytes in <code>mlx</code>.</p>
<p>If <code>T</code> is an class type, the function:</p>
<ul>
<li>Reverses the order of bytes of all data members of <code>mlx</code>
that have types or arrays of
types that meet the <code>EndianReversible</code> or <code>EndianReversibleInplace</code>
requirements, and;</li>
<li>Is a non-member function in the same namespace as <code>T</code> that
can be found by argument dependent lookup (ADL).&nbsp; </li>
</ul>
</td>
</tr> </tr>
</table> </table>
<blockquote>
<p> [<i>Note:</i> A user-defined type meets these requirements by defining a
non-member function in the same namespace as the UDT itself so that the function
can be found by argument dependent lookup (ADL).&nbsp; <i>&mdash;end note</i>]</p>
<p> [<i>Note:</i> Because there is a function template for <code>endian_reverse_inplace</code> <p> [<i>Note:</i> Because there is a function template for <code>endian_reverse_inplace</code>
that calls <code>endian_reverse</code>, only <code>endian_reverse</code> that calls <code>endian_reverse</code>, only <code>endian_reverse</code>
is required for a user-defined type to meet the <code>Reversible</code> is required for a user-defined type to meet the <code>EndianReversibleInplace</code>
requirements. User-defined types may provide <code>endian_reverse_inplace</code> requirements. Although User-defined types are not required to supply an <code>endian_reverse_inplace</code>
for improved efficiency. <i>&mdash;end note</i>]</p> function, doing so may improved efficiency. <i>&nbsp;&mdash;end note</i>]</p>
<p> <span style="background-color: #FFFF00">This still isn&#39;t right. There are
really separate Reversible and </span><span style="background-color: #FFFF00">
ReversibleHere</span><span style="background-color: #FFFF00"> requirements, and
the </span><span style="background-color: #FFFF00">endian_reverse_here</span><span style="background-color: #FFFF00">
template&#39;s type should be Reversible. See the udt_conversion_example for a type
that is ReversibleHere but not Reversible and works just fine.</span></p>
</blockquote>
<h4> <a name="Customization-points">Customization points</a> for user-defined types (<a name="UDT">UDT</a>s)</h4> <h4> <a name="Customization-points">Customization points</a> for user-defined types (<a name="UDT">UDT</a>s)</h4>
<p> This subsection describes requirements on the endian library&#39;s own <p> This subsection describes requirements on the Endian library&#39;s implementation.</p>
implementation.</p>
<p> The endianness reversal function templates that return values are <p> The library&#39;s function templates requiring <code>
<a href="#EndianReversible">EndianReversible</a></code> are
required to perform reversal of endianness if needed by making an unqualified required to perform reversal of endianness if needed by making an unqualified
call to <code>endian_reverse(<i>argument</i>)</code>, as described in the call to <code>endian_reverse()</code>.</p>
preceding table.</p>
<p> The endianness reversal function templates that modify their argument in <p> The library&#39;s function templates requiring <code>
place, except <code>endian_reverse_inplace</code> itself, are required to perform reversal of endianness if needed by making an <a href="#EndianReversibleInplace">EndianReversibleInplace</a></code> are required to perform reversal of endianness if needed by making an
unqualified call to <code>endian_reverse_inplace(<i>argument</i>)</code>, unqualified call to <code>endian_reverse_inplace()</code>.</p>
as described in the preceding table.</p>
<p> See <a href="../example/udt_conversion_example.cpp"> <p> See <a href="../example/udt_conversion_example.cpp">
udt_conversion_example.cpp</a> for an example user-defined type.</p> udt_conversion_example.cpp</a> for an example user-defined type.</p>
@@ -233,90 +248,93 @@ uint64_t endian_reverse(uint64_t x) noexcept;
float endian_reverse(float x) noexcept; float endian_reverse(float x) noexcept;
double endian_reverse(double x) noexcept;</pre> double endian_reverse(double x) noexcept;</pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <i><code>x</code></i>, with the order of its <p dir="ltr"><i>Returns:</i> <i><code>x</code></i>, with the order of its
constituent bytes reversed.</p> constituent bytes reversed.</p>
<p><i>Remarks:</i> Meet the <code>EndianReversible</code> requirements.</p>
<p>[<i>Note:</i> The Boost.Endian library does not provide overloads for the C++ standard library
supplied types. <i>&mdash;end note</i>]</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversible&gt;
Reversible big_to_native(Reversible x) noexcept;</pre> EndianReversible big_to_native(EndianReversible x) noexcept;</pre>
<blockquote> <blockquote>
<p> <p>
<i>Returns:</i> <code>conditional_reverse&lt;order::big, <i>Returns:</i> <code>conditional_reverse&lt;order::big,
order::native&gt;(x)</code>.</p> order::native&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversible&gt;
Reversible native_to_big(Reversible x) noexcept; </pre> EndianReversible native_to_big(EndianReversible x) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <code>conditional_reverse&lt;order::native, order::big&gt;(x)</code>.</p> <p><i>Returns:</i> <code>conditional_reverse&lt;order::native, order::big&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversible&gt;
Reversible little_to_native(Reversible x) noexcept; </pre> EndianReversible little_to_native(EndianReversible x) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <code>conditional_reverse&lt;order::little, order::native&gt;(x)</code>.</p> <p><i>Returns:</i> <code>conditional_reverse&lt;order::little, order::native&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversible&gt;
Reversible native_to_little(Reversible x) noexcept; </pre> EndianReversible native_to_little(EndianReversible x) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <code>conditional_reverse&lt;order::native, order::little&gt;(x)</code>.</p> <p><i>Returns:</i> <code>conditional_reverse&lt;order::native, order::little&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;order O1, order O2, class Reversible&gt; <pre>template &lt;order O1, order O2, class EndianReversible&gt;
Reversible conditional_reverse(Reversible x) noexcept; </pre> EndianReversible conditional_reverse(EndianReversible x) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <code>x</code> if <code>O1 == O2,</code> otherwise <p><i>Returns:</i> <code>x</code> if <code>O1 == O2,</code> otherwise
<code>endian_reverse(x)</code>.</p> <code>endian_reverse(x)</code>.</p>
<p><i>Remarks: </i>Whether <code>x</code> or <code>endian_reverse(x)</code> <p><i>Remarks: </i>Whether <code>x</code> or <code>endian_reverse(x)</code>
is to be returned shall be determined at compile time.</p> is to be returned shall be determined at compile time.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversible&gt;
Reversible conditional_reverse(Reversible x, EndianReversible conditional_reverse(EndianReversible x,
order order1, order order2) noexcept; </pre> order order1, order order2) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Returns:</i> <code>order1 == order2 ? x : endian_reverse(x)</code>.</p> <p><i>Returns:</i> <code>order1 == order2 ? x : endian_reverse(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversible&gt;
void endian_reverse_inplace(Reversible&amp; x) noexcept; </pre> void endian_reverse_inplace(EndianReversible&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Effects:</i> <code>x</code> <code>= endian_reverse(x)</code>.</p> <p><i>Effects:</i> <code>x</code> <code>= endian_reverse(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversibleInplace&gt;
void big_to_native_inplace(Reversible&amp; x) noexcept; </pre> void big_to_native_inplace(EndianReversibleInplace&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_inplace&lt;order::big, <i>Effects:</i> <code>conditional_reverse_inplace&lt;order::big,
order::native&gt;(x)</code>.</p> order::native&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversibleInplace&gt;
void native_to_big_inplace(Reversible&amp; x) noexcept; </pre> void native_to_big_inplace(EndianReversibleInplace&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_inplace&lt;order::native, <i>Effects:</i> <code>conditional_reverse_inplace&lt;order::native,
order::big&gt;(x)</code>.</p> order::big&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversibleInplace&gt;
void little_to_native_inplace(Reversible&amp; x) noexcept; </pre> void little_to_native_inplace(EndianReversibleInplace&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_inplace&lt;order::little, order::native&gt;(x)</code>.</p> <i>Effects:</i> <code>conditional_reverse_inplace&lt;order::little, order::native&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversibleInplace&gt;
void native_to_little_inplace(Reversible&amp; x) noexcept; </pre> void native_to_little_inplace(EndianReversibleInplace&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_inplace&lt;order::native, <i>Effects:</i> <code>conditional_reverse_inplace&lt;order::native,
order::little&gt;(x)</code>.</p> order::little&gt;(x)</code>.</p>
</blockquote> </blockquote>
<pre>template &lt;order O1, order O2, class Reversible&gt; <pre>template &lt;order O1, order O2, class EndianReversibleInplace&gt;
void conditional_reverse_inplace(Reversible&amp; x) noexcept; </pre> void conditional_reverse_inplace(EndianReversibleInplace&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Effects:</i> None if <code>O1 == O2,</code> otherwise <p><i>Effects:</i> None if <code>O1 == O2,</code> otherwise
<code>endian_reverse_inplace(x)</code>.</p> <code>endian_reverse_inplace(x)</code>.</p>
<p><i>Remarks: </i>Which effect applies shall be determined at compile time.</p> <p><i>Remarks: </i>Which effect applies shall be determined at compile time.</p>
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class EndianReversibleInplace&gt;
void conditional_reverse_inplace(Reversible&amp; x, void conditional_reverse_inplace(EndianReversibleInplace&amp; x,
order order1, order order2) noexcept; </pre> order order1, order order2) noexcept; </pre>
@@ -348,7 +366,7 @@ Pierre Talbot provided the <code>int8_t endian_reverse()</code> and templated
<code>endian_reverse_inplace()</code> implementations.</p> <code>endian_reverse_inplace()</code> implementations.</p>
<hr> <hr>
<p>Last revised: <p>Last revised:
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->10 December, 2014<!--webbot bot="Timestamp" endspan i-checksum="38633" --></p> <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->11 December, 2014<!--webbot bot="Timestamp" endspan i-checksum="38635" --></p>
<p>© Copyright Beman Dawes, 2011, 2013</p> <p>© Copyright Beman Dawes, 2011, 2013</p>
<p>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> <p>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>

View File

@@ -66,33 +66,35 @@ namespace endian
inline double endian_reverse(double x) BOOST_NOEXCEPT; inline double endian_reverse(double x) BOOST_NOEXCEPT;
// reverse byte order unless native endianness is big // reverse byte order unless native endianness is big
template <class Reversible > template <class EndianReversible >
inline Reversible big_to_native(Reversible x) BOOST_NOEXCEPT; inline EndianReversible big_to_native(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is big, otherwise endian_reverse(x) // Returns: x if native endian order is big, otherwise endian_reverse(x)
template <class Reversible > template <class EndianReversible >
inline Reversible native_to_big(Reversible x) BOOST_NOEXCEPT; inline EndianReversible native_to_big(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is big, otherwise endian_reverse(x) // Returns: x if native endian order is big, otherwise endian_reverse(x)
// reverse byte order unless native endianness is little // reverse byte order unless native endianness is little
template <class Reversible > template <class EndianReversible >
inline Reversible little_to_native(Reversible x) BOOST_NOEXCEPT; inline EndianReversible little_to_native(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is little, otherwise endian_reverse(x) // Returns: x if native endian order is little, otherwise endian_reverse(x)
template <class Reversible > template <class EndianReversible >
inline Reversible native_to_little(Reversible x) BOOST_NOEXCEPT; inline EndianReversible native_to_little(EndianReversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is little, otherwise endian_reverse(x) // Returns: x if native endian order is little, otherwise endian_reverse(x)
// generic conditional reverse byte order // generic conditional reverse byte order
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible> template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To,
inline Reversible conditional_reverse(Reversible from) BOOST_NOEXCEPT; class EndianReversible>
inline EndianReversible conditional_reverse(EndianReversible from) BOOST_NOEXCEPT;
// Returns: If From == To have different values, from. // Returns: If From == To have different values, from.
// Otherwise endian_reverse(from). // Otherwise endian_reverse(from).
// Remarks: The From == To test, and as a consequence which form the return takes, is // Remarks: The From == To test, and as a consequence which form the return takes, is
// is determined at compile time. // is determined at compile time.
// runtime conditional reverse byte order // runtime conditional reverse byte order
template <class Reversible > template <class EndianReversible >
inline Reversible conditional_reverse(Reversible from, inline EndianReversible conditional_reverse(EndianReversible from,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT; BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order)
BOOST_NOEXCEPT;
// Returns: from_order == to_order ? from : endian_reverse(from). // Returns: from_order == to_order ? from : endian_reverse(from).
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
@@ -123,33 +125,33 @@ namespace endian
//------------------------------------------------------------------------------------// //------------------------------------------------------------------------------------//
// reverse in place // reverse in place
template <class Value> template <class EndianReversible>
inline void endian_reverse_inplace(Value& x) BOOST_NOEXCEPT; inline void endian_reverse_inplace(EndianReversible& x) BOOST_NOEXCEPT;
// Effects: x = endian_reverse(x) // Effects: x = endian_reverse(x)
// reverse in place unless native endianness is big // reverse in place unless native endianness is big
template <class Reversible> template <class EndianReversibleInplace>
inline void big_to_native_inplace(Reversible& x) BOOST_NOEXCEPT; inline void big_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x) // Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x)
template <class Reversible> template <class EndianReversibleInplace>
inline void native_to_big_inplace(Reversible& x) BOOST_NOEXCEPT; inline void native_to_big_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x) // Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x)
// reverse in place unless native endianness is little // reverse in place unless native endianness is little
template <class Reversible> template <class EndianReversibleInplace>
inline void little_to_native_inplace(Reversible& x) BOOST_NOEXCEPT; inline void little_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x); // Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x);
template <class Reversible> template <class EndianReversibleInplace>
inline void native_to_little_inplace(Reversible& x) BOOST_NOEXCEPT; inline void native_to_little_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x); // Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x);
// generic conditional reverse in place // generic conditional reverse in place
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible> template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversibleInplace>
inline void conditional_reverse_inplace(Reversible& x) BOOST_NOEXCEPT; inline void conditional_reverse_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
// runtime reverse in place // runtime reverse in place
template <class Reversible> template <class EndianReversibleInplace>
inline void conditional_reverse_inplace(Reversible& x, inline void conditional_reverse_inplace(EndianReversibleInplace& x,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order)
BOOST_NOEXCEPT; BOOST_NOEXCEPT;
@@ -296,8 +298,8 @@ namespace endian
return detail::std_endian_reverse(x); return detail::std_endian_reverse(x);
} }
template <class Reversible > template <class EndianReversible >
inline Reversible big_to_native(Reversible x) BOOST_NOEXCEPT inline EndianReversible big_to_native(EndianReversible x) BOOST_NOEXCEPT
{ {
# ifdef BOOST_BIG_ENDIAN # ifdef BOOST_BIG_ENDIAN
return x; return x;
@@ -306,8 +308,8 @@ namespace endian
# endif # endif
} }
template <class Reversible > template <class EndianReversible >
inline Reversible native_to_big(Reversible x) BOOST_NOEXCEPT inline EndianReversible native_to_big(EndianReversible x) BOOST_NOEXCEPT
{ {
# ifdef BOOST_BIG_ENDIAN # ifdef BOOST_BIG_ENDIAN
return x; return x;
@@ -316,8 +318,8 @@ namespace endian
# endif # endif
} }
template <class Reversible > template <class EndianReversible >
inline Reversible little_to_native(Reversible x) BOOST_NOEXCEPT inline EndianReversible little_to_native(EndianReversible x) BOOST_NOEXCEPT
{ {
# ifdef BOOST_LITTLE_ENDIAN # ifdef BOOST_LITTLE_ENDIAN
return x; return x;
@@ -326,8 +328,8 @@ namespace endian
# endif # endif
} }
template <class Reversible > template <class EndianReversible >
inline Reversible native_to_little(Reversible x) BOOST_NOEXCEPT inline EndianReversible native_to_little(EndianReversible x) BOOST_NOEXCEPT
{ {
# ifdef BOOST_LITTLE_ENDIAN # ifdef BOOST_LITTLE_ENDIAN
return x; return x;
@@ -340,7 +342,7 @@ namespace endian
{ {
// Primary template and specializations to support endian_reverse(). // Primary template and specializations to support endian_reverse().
// See rationale in endian_reverse() below. // See rationale in endian_reverse() below.
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible> template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversible>
class value_converter ; // primary template class value_converter ; // primary template
template <class T> class value_converter <order::big, order::big, T> template <class T> class value_converter <order::big, order::big, T>
{public: T operator()(T x) BOOST_NOEXCEPT {return x;}}; {public: T operator()(T x) BOOST_NOEXCEPT {return x;}};
@@ -353,18 +355,18 @@ namespace endian
} }
// generic conditional reverse // generic conditional reverse
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible> template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversible>
inline Reversible conditional_reverse(Reversible from) BOOST_NOEXCEPT { inline EndianReversible conditional_reverse(EndianReversible from) BOOST_NOEXCEPT {
// work around lack of function template partial specialization by instantiating // work around lack of function template partial specialization by instantiating
// a function object of a class that is partially specialized on the two order // a function object of a class that is partially specialized on the two order
// template parameters, and then calling its operator(). // template parameters, and then calling its operator().
detail::value_converter <From, To, Reversible> tmp; detail::value_converter <From, To, EndianReversible> tmp;
return tmp(from); return tmp(from);
} }
// runtime conditional reverse // runtime conditional reverse
template <class Reversible > template <class EndianReversible >
inline Reversible conditional_reverse(Reversible from, inline EndianReversible conditional_reverse(EndianReversible from,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT
{ {
return from_order == to_order ? from : endian_reverse(from); return from_order == to_order ? from : endian_reverse(from);
@@ -375,41 +377,41 @@ namespace endian
//--------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------//
// reverse in place // reverse in place
template <class Value> template <class EndianReversible>
inline void endian_reverse_inplace(Value& x) BOOST_NOEXCEPT inline void endian_reverse_inplace(EndianReversible& x) BOOST_NOEXCEPT
{ {
x = endian_reverse(x); x = endian_reverse(x);
} }
template <class Reversible> template <class EndianReversibleInplace>
# ifdef BOOST_BIG_ENDIAN # ifdef BOOST_BIG_ENDIAN
inline void big_to_native_inplace(Reversible&) BOOST_NOEXCEPT {} inline void big_to_native_inplace(EndianReversibleInplace&) BOOST_NOEXCEPT {}
# else # else
inline void big_to_native_inplace(Reversible& x) BOOST_NOEXCEPT inline void big_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT
{ endian_reverse_inplace(x); } { endian_reverse_inplace(x); }
# endif # endif
template <class Reversible> template <class EndianReversibleInplace>
# ifdef BOOST_BIG_ENDIAN # ifdef BOOST_BIG_ENDIAN
inline void native_to_big_inplace(Reversible&) BOOST_NOEXCEPT {} inline void native_to_big_inplace(EndianReversibleInplace&) BOOST_NOEXCEPT {}
# else # else
inline void native_to_big_inplace(Reversible& x) BOOST_NOEXCEPT inline void native_to_big_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT
{ {
endian_reverse_inplace(x); endian_reverse_inplace(x);
} }
# endif # endif
template <class Reversible> template <class EndianReversibleInplace>
# ifdef BOOST_LITTLE_ENDIAN # ifdef BOOST_LITTLE_ENDIAN
inline void little_to_native_inplace(Reversible&) BOOST_NOEXCEPT {} inline void little_to_native_inplace(EndianReversibleInplace&) BOOST_NOEXCEPT {}
# else # else
inline void little_to_native_inplace(Reversible& x) BOOST_NOEXCEPT inline void little_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT
{ endian_reverse_inplace(x); } { endian_reverse_inplace(x); }
# endif # endif
template <class Reversible> template <class EndianReversibleInplace>
# ifdef BOOST_LITTLE_ENDIAN # ifdef BOOST_LITTLE_ENDIAN
inline void native_to_little_inplace(Reversible&) BOOST_NOEXCEPT {} inline void native_to_little_inplace(EndianReversibleInplace&) BOOST_NOEXCEPT {}
# else # else
inline void native_to_little_inplace(Reversible& x) BOOST_NOEXCEPT inline void native_to_little_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT
{ {
endian_reverse_inplace(x); endian_reverse_inplace(x);
} }
@@ -420,7 +422,7 @@ namespace endian
// Primary template and specializations support generic // Primary template and specializations support generic
// endian_reverse_inplace(). // endian_reverse_inplace().
// See rationale in endian_reverse_inplace() below. // See rationale in endian_reverse_inplace() below.
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible> template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversibleInplace>
class converter; // primary template class converter; // primary template
template <class T> class converter<order::big, order::big, T> template <class T> class converter<order::big, order::big, T>
{public: void operator()(T&) BOOST_NOEXCEPT {/*no effect*/}}; {public: void operator()(T&) BOOST_NOEXCEPT {/*no effect*/}};
@@ -433,19 +435,19 @@ namespace endian
} // namespace detail } // namespace detail
// generic conditional reverse in place // generic conditional reverse in place
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible> template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversibleInplace>
inline void conditional_reverse_inplace(Reversible& x) BOOST_NOEXCEPT inline void conditional_reverse_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT
{ {
// work around lack of function template partial specialization by instantiating // work around lack of function template partial specialization by instantiating
// a function object of a class that is partially specialized on the two order // a function object of a class that is partially specialized on the two order
// template parameters, and then calling its operator(). // template parameters, and then calling its operator().
detail::converter<From, To, Reversible> tmp; detail::converter<From, To, EndianReversibleInplace> tmp;
tmp(x); // call operator () tmp(x); // call operator ()
} }
// runtime reverse in place // runtime reverse in place
template <class Reversible> template <class EndianReversibleInplace>
inline void conditional_reverse_inplace(Reversible& x, inline void conditional_reverse_inplace(EndianReversibleInplace& x,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order)
BOOST_NOEXCEPT BOOST_NOEXCEPT
{ {

View File

@@ -90,7 +90,7 @@ struct construct
static void test() static void test()
{ {
T2 o2(1); T2 o2(1);
T1 o1(o2); T1 o1(o2); // TODO: does this make sense for char types?
++o1; // quiet gcc unused variable warning ++o1; // quiet gcc unused variable warning
} }
}; };