Rename "reverse_endianness" to "endian_reverse". Shorter but still plenty explicit. See bikeshed.txt for alternatives considered.

This commit is contained in:
Beman
2014-12-10 08:30:30 -05:00
parent e4466edf4e
commit dcca2835a9
8 changed files with 191 additions and 182 deletions

View File

@@ -8,17 +8,17 @@ reverse_endianness reverse_endianness_in_place
endian_reverse endian_reverse_in_place
" endian_reverse_in_situ
" endian_reverse_here
" endian_reverse_this
" endian_reverse_self
" endian_reverse_arg
" endian_reverse_in
" endian_reverse_this <-----
" endian_reverse_self
" endian_reverse_arg
" endian_reverse_in
reverse reverse_in_place
reverse_endian reverse_endian_in_place
swap_endianness swap_endianness_in_place
swap_endian swap_endian_in_place
endian_swap endian_swap_in_place
endian_swap endian_swap_this
flip_endianness flip_endianness_in_place
flip_endian flip_endian_in_place
@@ -30,29 +30,28 @@ reverse_order reverse_order_in_place
Key points:
* These names are defined in a user namespace as customization points to be found by
* The above names are defined in a user namespace as customization points to be found by
ADL, and so cannot depend on the enclosing namespace name to signal readers that they
are related to endianness.
* These functions are rarely called directly by user code, which is more likely to use
* The above functions are rarely called directly by user code, which is more likely to use
the various conditional functions instead. So explicitness is more important than
brevity.
big_to_native native_to_big reverse_unless_native_big little_to_native native_to_little reverse_unless_native_little
reverse_if_not_big
reverse_if_little
reverse_unless_big
Conditional names
big_to_host host_to_big reverse_unless_host_big
reverse_if_host_little
big_to_native native_to_big little_to_native native_to_little
big_to_host host_to_big
be_to_ne ne_to_be
from_big, to_big, reverse_unless_big
from_big, to_big
big_to_native big_to_native
native_to_big native_to_big
reverse_unless_native_big ------ <------
conditional_reverse reverse_unless_same<...>() <------
runtime_conditional_reverse reverse_unless_same() <------
conditional_reverse runtime_conditional_reverse
conditional_reverse conditional_reverse <------
merriam-webster.com/dictionary

View File

@@ -1,4 +1,4 @@
<html>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
@@ -515,7 +515,7 @@ is a constant of type <code>value_type</code> with <code>Nbits</code> low-order
bits set to one.</p>
<p><i>Remarks:</i> If <code>Align</code> is <code>align::yes</code> then
endianness conversion if required is performed by <code>
boost::endian::reverse_endianness</code>.</p>
boost::endian::endian_reverse</code>.</p>
</blockquote>
<pre><code>endian_buffer&amp; <a name="operator-eq">operator=</a>(T v) noexcept;</code></pre>
<blockquote>
@@ -525,7 +525,7 @@ boost::endian::reverse_endianness</code>.</p>
<p><i>Returns:</i> <code>*this</code>.</p>
<p><i>Remarks:</i> If <code>Align</code> is <code>align::yes</code> then
endianness conversion if required is performed by <code>
boost::endian::reverse_endianness</code>.</p>
boost::endian::endian_reverse</code>.</p>
</blockquote>
<pre>value_type <a name="value">value</a>()<code> const noexcept;</code></pre>
<blockquote>
@@ -533,7 +533,7 @@ boost::endian::reverse_endianness</code>.</p>
if necessary and having the endianness of the native platform.</p>
<p><i>Remarks:</i> If <code>Align</code> is <code>align::yes</code> then
endianness conversion if required is performed by <code>
boost::endian::reverse_endianness</code>.</p>
boost::endian::endian_reverse</code>.</p>
</blockquote>
<pre><code>const char* <a name="data">data</a>() const noexcept;</code></pre>
<blockquote>

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>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
@@ -18,7 +18,7 @@
<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" border="0" width="277" height="86" ></a></td>
<td align="middle">
<b>
<font size="6">Endian Conversion Functions</font></b></td>
<font size="6">Endian Conversion Functions</font></b></td>
</tr>
</table>
@@ -96,16 +96,16 @@ namespace endian
native = <b><i>implementation-defined</i></b> // same as order::big or order::little<b><i>
</i></b>};
int8_t <a href="#reverse_endianness">reverse_endianness</a>(int8_t x) noexcept;
int16_t <a href="#reverse_endianness">reverse_endianness</a>(int16_t x) noexcept;
int32_t <a href="#reverse_endianness">reverse_endianness</a>(int32_t x) noexcept;
int64_t <a href="#reverse_endianness">reverse_endianness</a>(int64_t x) noexcept;
uint8_t <a href="#reverse_endianness">reverse_endianness</a>(uint8_t x) noexcept;
uint16_t <a href="#reverse_endianness">reverse_endianness</a>(uint16_t x) noexcept;
uint32_t <a href="#reverse_endianness">reverse_endianness</a>(uint32_t x) noexcept;
uint64_t <a href="#reverse_endianness">reverse_endianness</a>(uint64_t x) noexcept;
float <a href="#reverse_endianness">reverse_endianness</a>(float x) noexcept;
double <a href="#reverse_endianness">reverse_endianness</a>(double 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;
int32_t <a href="#endian_reverse">endian_reverse</a>(int32_t x) noexcept;
int64_t <a href="#endian_reverse">endian_reverse</a>(int64_t x) noexcept;
uint8_t <a href="#endian_reverse">endian_reverse</a>(uint8_t x) noexcept;
uint16_t <a href="#endian_reverse">endian_reverse</a>(uint16_t x) noexcept;
uint32_t <a href="#endian_reverse">endian_reverse</a>(uint32_t x) noexcept;
uint64_t <a href="#endian_reverse">endian_reverse</a>(uint64_t x) noexcept;
float <a href="#endian_reverse">endian_reverse</a>(float x) noexcept;
double <a href="#endian_reverse">endian_reverse</a>(double x) noexcept;
template &lt;class Reversible&gt;
Reversible big_to_native(Reversible x) noexcept;
@@ -122,7 +122,7 @@ namespace endian
order order1, order order2) noexcept;
template &lt;class Reversible&gt;
void reverse_endianness_in_place(Reversible&amp; x) noexcept;
void endian_reverse_in_place(Reversible&amp; x) noexcept;
template &lt;class Reversible&gt;
void big_to_native_in_place(Reversible&amp; x) noexcept;
@@ -160,7 +160,7 @@ instantiating a template.</p>
</tr>
<tr>
<td valign="top">
<p><code>reverse_endianness(x)</code></td>
<p><code>endian_reverse(x)</code></td>
<td valign="top">
<code>x</code> is a value of a possibly <code>const</code> type convertible
to <code>Reversible</code>.</td>
@@ -170,7 +170,7 @@ instantiating a template.</p>
</tr>
<tr>
<td valign="top">
<code>reverse_endianness_in_place(x)</code></td>
<code>endian_reverse_in_place(x)</code></td>
<td valign="top">
<code>x</code> is a
modifiable lvalue of type <code>Reversible</code>.</td>
@@ -186,10 +186,10 @@ modifiable lvalue of type <code>Reversible</code>.</td>
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>reverse_endianness_in_place</code>
that calls <code>reverse_endianness</code>, only <code>reverse_endianness</code>
<p> [<i>Note:</i> Because there is a function template for <code>endian_reverse_in_place</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>
requirements. User-defined types may provide <code>reverse_endianness_in_place</code>
requirements. User-defined types may provide <code>endian_reverse_in_place</code>
for improved efficiency. <i>&mdash;end note</i>]</p>
</blockquote>
@@ -201,28 +201,28 @@ implementation.</p>
<p> The endianness reversal function templates that return values are
required to perform reversal of endianness if needed by making an unqualified
call to <code>reverse_endianness(<i>argument</i>)</code>, as described in the
call to <code>endian_reverse(<i>argument</i>)</code>, as described in the
preceding table.</p>
<p> The endianness reversal function templates that modify their argument in
place, except <code>reverse_endianness_in_place</code> itself, are required to perform reversal of endianness if needed by making an
unqualified call to <code>reverse_endianness_in_place(<i>argument</i>)</code>,
place, except <code>endian_reverse_in_place</code> itself, are required to perform reversal of endianness if needed by making an
unqualified call to <code>endian_reverse_in_place(<i>argument</i>)</code>,
as described in the preceding table.</p>
<p> See <a href="../example/udt_conversion_example.cpp">
udt_conversion_example.cpp</a> for an example user-defined type.</p>
<h3><a name="Functions">Functions</a></h3>
<pre><a name="reverse_endianness"></a>int8_t reverse_endianness(int8_t x) noexcept;
int16_t reverse_endianness(int16_t x) noexcept;
int32_t reverse_endianness(int32_t x) noexcept;
int64_t reverse_endianness(int64_t x) noexcept;
uint8_t reverse_endianness(uint8_t x) noexcept;
uint16_t reverse_endianness(uint16_t x) noexcept;
uint32_t reverse_endianness(uint32_t x) noexcept;
uint64_t reverse_endianness(uint64_t x) noexcept;
float reverse_endianness(float x) noexcept;
double reverse_endianness(double x) noexcept;</pre>
<pre><a name="endian_reverse"></a>int8_t endian_reverse(int8_t x) noexcept;
int16_t endian_reverse(int16_t x) noexcept;
int32_t endian_reverse(int32_t x) noexcept;
int64_t endian_reverse(int64_t x) noexcept;
uint8_t endian_reverse(uint8_t x) noexcept;
uint16_t endian_reverse(uint16_t x) noexcept;
uint32_t endian_reverse(uint32_t x) noexcept;
uint64_t endian_reverse(uint64_t x) noexcept;
float endian_reverse(float x) noexcept;
double endian_reverse(double x) noexcept;</pre>
<blockquote>
<p><i>Returns:</i> <i><code>x</code></i>, with the order of its
constituent bytes reversed.</p>
@@ -254,22 +254,22 @@ Reversible native_to_little(Reversible x) noexcept; </pre>
Reversible conditional_reverse(Reversible x) noexcept; </pre>
<blockquote>
<p><i>Returns:</i> <code>x</code> if <code>O1 == O2,</code> otherwise
<code>reverse_endianness(x)</code>.</p>
<p><i>Remarks: </i>Whether <code>x</code> or <code>reverse_endianness(x)</code>
<code>endian_reverse(x)</code>.</p>
<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>
</blockquote>
<pre>template &lt;class Reversible&gt;
Reversible runtime_conditional_reverse(Reversible x,
order order1, order order2) noexcept; </pre>
<blockquote>
<p><i>Returns:</i> <code>order1 == order2 ? x : reverse_endianness(x)</code>.</p>
<p><i>Returns:</i> <code>order1 == order2 ? x : endian_reverse(x)</code>.</p>
</blockquote>
<pre>template &lt;class Reversible&gt;
void reverse_endianness_in_place(Reversible&amp; x) noexcept; </pre>
void endian_reverse_in_place(Reversible&amp; x) noexcept; </pre>
<blockquote>
<p><i>Effects:</i> <code>x</code> <code>= reverse_endianness(x)</code>.</p>
<p><i>Effects:</i> <code>x</code> <code>= endian_reverse(x)</code>.</p>
</blockquote>
<pre>template &lt;class Reversible&gt;
@@ -303,7 +303,7 @@ void native_to_little_in_place(Reversible&amp; x) noexcept; </pre>
void conditional_reverse_in_place(Reversible&amp; x) noexcept; </pre>
<blockquote>
<p><i>Effects:</i> None if <code>O1 == O2,</code> otherwise
<code>reverse_endianness_in_place(x)</code>.</p>
<code>endian_reverse_in_place(x)</code>.</p>
<p><i>Remarks: </i>Which effect applies shall be determined at compile time.</p>
</blockquote>
<pre>template &lt;class Reversible&gt;
@@ -312,7 +312,7 @@ void runtime_conditional_reverse_in_place(Reversible&amp; x,
<blockquote>
<p><i>Effects: </i>If <code>order1 == order2</code> then <code>reverse_endianness_in_place(x)</code>.</p>
<p><i>Effects: </i>If <code>order1 == order2</code> then <code>endian_reverse_in_place(x)</code>.</p>
</blockquote>
@@ -321,7 +321,7 @@ void runtime_conditional_reverse_in_place(Reversible&amp; x,
<p>See the <a href="index.html#FAQ">Endian home page</a> FAQ for a library-wide
FAQ.</p>
<p><b>Why are the template versions of <code>reverse()</code> and <code>reverse_endianness()</code>
<p><b>Why are the template versions of <code>reverse()</code> and <code>endian_reverse()</code>
in a detail namespace?</b></p>
<blockquote>
@@ -347,7 +347,7 @@ provided.</p>
<h2><a name="Acknowledgements">Acknowledgements</a></h2><p>Tomas Puverle was instrumental in identifying and articulating the need to
support endian conversion as separate from endian integer types. Phil Endecott suggested the form of the value returning signatures. Vicente Botet and other reviewers suggested supporting floating point types and user defined types. General reverse template implementation approach using std::reverse suggested by Mathias Gaunard. Portable implementation approach for 16, 32, and 64-bit integers suggested by tymofey, with avoidance of undefined behavior as suggested by Giovanni Piero Deretta, and a further refinement suggested by Pyry Jahkola. Intrinsic builtins implementation approach for 16, 32, and 64-bit integers suggested by several reviewers, and by David Stone, who provided his Boost licensed macro implementation that became the starting point for <a href="../include/boost/endian/detail/intrinsic.hpp">boost/endian/detail/intrinsic.hpp</a>.
Pierre Talbot provided the <code>int8_t reverse_endianness()</code> and templated
Pierre Talbot provided the <code>int8_t endian_reverse()</code> and templated
<code>reverse()</code> implementations.</p>
<hr>
<p>Last revised:

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>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
@@ -678,7 +678,7 @@ and 16, 32, and 64-bit aligned integers.</p>
<li><code>order::native</code> is now a synonym for <code>order::big</code>
or <code>order::little</code> according to the endianness of the platform, as
requested. This reduces the number of template specializations required.</li>
<li><code>reverse_endianness()</code> overloads for <code>int8_t</code> and <code>
<li><code>endian_reverse()</code> overloads for <code>int8_t</code> and <code>
uint8_t</code> have been added for improved generality. (Pierre Talbot)</li>
<li>Overloads of <code>reverse()</code> have been replaced with a single <code>
reverse()</code> template. (Pierre Talbot)</li>

View File

@@ -20,52 +20,54 @@ using std::cout;
using std::endl;
using boost::int32_t;
class UDT
namespace user
{
public:
UDT() : id_(0), value_(0.0) {desc_[0] = '\0';}
UDT(int32_t id, float value, const char* desc) : id_(id), value_(value)
class UDT
{
std::strncpy(desc_, desc, sizeof(desc_)-1);
desc_[sizeof(desc_)-1] = '\0';
}
int32_t id() const {return id_;}
float value() const {return value_;}
const char* desc() const {return desc_;}
void id(int32_t x) {id_ = x;}
void value(float v) {value_ = v;}
void desc(const char* s)
public:
UDT() : id_(0), value_(0.0) {desc_[0] = '\0';}
UDT(int32_t id, float value, const char* desc) : id_(id), value_(value)
{
std::strncpy(desc_, desc, sizeof(desc_)-1);
desc_[sizeof(desc_)-1] = '\0';
}
int32_t id() const {return id_;}
float value() const {return value_;}
const char* desc() const {return desc_;}
void id(int32_t x) {id_ = x;}
void value(float v) {value_ = v;}
void desc(const char* s)
{
std::strncpy(desc_, s, sizeof(desc_)-1);
desc_[sizeof(desc_-1)] = '\0';
}
friend void endian_reverse_in_place(UDT&);
private:
int32_t id_;
float value_;
char desc_[56]; // '/0'
};
void endian_reverse_in_place(UDT& x)
{
std::strncpy(desc_, s, sizeof(desc_)-1);
desc_[sizeof(desc_-1)] = '\0';
boost::endian::endian_reverse_in_place(x.id_);
boost::endian::endian_reverse_in_place(x.value_);
}
friend UDT reverse_endianness(const UDT&);
friend void reverse_endianness_in_place(UDT&);
private:
int32_t id_;
float value_;
char desc_[56]; // '/0'
};
void reverse_endianness_in_place(UDT& x)
{
reverse_endianness_in_place(x.id_);
reverse_endianness_in_place(x.value_);
}
int main(int, char* [])
{
UDT x(1, 1.2345f, "Bingo!");
user::UDT x(1, 1.2345f, "Bingo!");
//cout << std::hex;
cout << "(1) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
reverse_endianness_in_place(x);
user::endian_reverse_in_place(x);
cout << "(2) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
reverse_endianness_in_place(x);
endian_reverse_in_place(x);
cout << "(3) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
conditional_reverse_in_place<order::little, order::big>(x);

View File

@@ -44,48 +44,48 @@ namespace endian
// user-defined types (UDTs) //
// //
// All return-by-value conversion function templates are required to be implemented in //
// terms of an unqualified call to "reverse_endianness(x)", a function returning the //
// terms of an unqualified call to "endian_reverse(x)", a function returning the //
// value of x with endianness reversed. This provides a customization point for any //
// UDT that provides a "reverse_endianness" free-function meeting the requirements. //
// UDT that provides a "endian_reverse" free-function meeting the requirements. //
// It must be defined in the same namespace as the UDT itself so that it will be found //
// by argument dependent lookup (ADL). //
// //
//--------------------------------------------------------------------------------------//
// customization for built-in arithmetic types
inline int8_t reverse_endianness(int8_t x) BOOST_NOEXCEPT;
inline int16_t reverse_endianness(int16_t x) BOOST_NOEXCEPT;
inline int32_t reverse_endianness(int32_t x) BOOST_NOEXCEPT;
inline int64_t reverse_endianness(int64_t x) BOOST_NOEXCEPT;
inline uint8_t reverse_endianness(uint8_t x) BOOST_NOEXCEPT;
inline uint16_t reverse_endianness(uint16_t x) BOOST_NOEXCEPT;
inline uint32_t reverse_endianness(uint32_t x) BOOST_NOEXCEPT;
inline uint64_t reverse_endianness(uint64_t x) BOOST_NOEXCEPT;
inline int8_t endian_reverse(int8_t x) BOOST_NOEXCEPT;
inline int16_t endian_reverse(int16_t x) BOOST_NOEXCEPT;
inline int32_t endian_reverse(int32_t x) BOOST_NOEXCEPT;
inline int64_t endian_reverse(int64_t x) BOOST_NOEXCEPT;
inline uint8_t endian_reverse(uint8_t x) BOOST_NOEXCEPT;
inline uint16_t endian_reverse(uint16_t x) BOOST_NOEXCEPT;
inline uint32_t endian_reverse(uint32_t x) BOOST_NOEXCEPT;
inline uint64_t endian_reverse(uint64_t x) BOOST_NOEXCEPT;
// TODO: Track progress of Floating-Point Typedefs Having Specified Widths proposal (N3626)
inline float reverse_endianness(float x) BOOST_NOEXCEPT;
inline double reverse_endianness(double x) BOOST_NOEXCEPT;
inline float endian_reverse(float x) BOOST_NOEXCEPT;
inline double endian_reverse(double x) BOOST_NOEXCEPT;
// reverse byte order unless native endianness is big
template <class Reversible >
inline Reversible big_to_native(Reversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is big, otherwise reverse_endianness(x)
// Returns: x if native endian order is big, otherwise endian_reverse(x)
template <class Reversible >
inline Reversible native_to_big(Reversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is big, otherwise reverse_endianness(x)
// Returns: x if native endian order is big, otherwise endian_reverse(x)
// reverse byte order unless native endianness is little
template <class Reversible >
inline Reversible little_to_native(Reversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is little, otherwise reverse_endianness(x)
// Returns: x if native endian order is little, otherwise endian_reverse(x)
template <class Reversible >
inline Reversible native_to_little(Reversible x) BOOST_NOEXCEPT;
// Returns: x if native endian order is little, otherwise reverse_endianness(x)
// Returns: x if native endian order is little, otherwise endian_reverse(x)
// generic conditional reverse byte order
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible>
inline Reversible conditional_reverse(Reversible from) BOOST_NOEXCEPT;
// Returns: If From == To have different values, from.
// Otherwise reverse_endianness(from).
// Otherwise endian_reverse(from).
// Remarks: The From == To test, and as a consequence which form the return takes, is
// is determined at compile time.
@@ -93,7 +93,7 @@ namespace endian
template <class Reversible >
inline Reversible runtime_conditional_reverse(Reversible from,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT;
// Returns: from_order == to_order ? from : reverse_endianness(from).
// Returns: from_order == to_order ? from : endian_reverse(from).
//------------------------------------------------------------------------------------//
@@ -113,7 +113,7 @@ namespace endian
// user-defined types (UDTs) //
// //
// All reverse in place function templates are required to be implemented in terms //
// of an unqualified call to "reverse_endianness_in_place(x)", a function reversing //
// of an unqualified call to "endian_reverse_in_place(x)", a function reversing //
// the endianness of x, which is a non-const reference. This provides a //
// customization point for any UDT that provides a "reverse_in_place" free-function //
// meeting the requirements. The free-function must be declared in the same //
@@ -124,24 +124,24 @@ namespace endian
// reverse in place
template <class Value>
inline void reverse_endianness_in_place(Value& x) BOOST_NOEXCEPT;
// Effects: x = reverse_endianness(x)
inline void endian_reverse_in_place(Value& x) BOOST_NOEXCEPT;
// Effects: x = endian_reverse(x)
// reverse in place unless native endianness is big
template <class Reversible>
inline void big_to_native_in_place(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise reverse_endianness_in_place(x)
// Effects: none if native byte-order is big, otherwise endian_reverse_in_place(x)
template <class Reversible>
inline void native_to_big_in_place(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise reverse_endianness_in_place(x)
// Effects: none if native byte-order is big, otherwise endian_reverse_in_place(x)
// reverse in place unless native endianness is little
template <class Reversible>
inline void little_to_native_in_place(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise reverse_endianness_in_place(x);
// Effects: none if native byte-order is little, otherwise endian_reverse_in_place(x);
template <class Reversible>
inline void native_to_little_in_place(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise reverse_endianness_in_place(x);
// Effects: none if native byte-order is little, otherwise endian_reverse_in_place(x);
// generic conditional reverse in place
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible>
@@ -160,11 +160,11 @@ namespace endian
// generic reverse function template implementation approach using std::reverse
// suggested by Mathias Gaunard. Primary motivation for inclusion is to have an
// independent implementation to test against. Secondary motivation is use by
// floating-point reverse_endianness, but that use is likely to be replace by a
// floating-point endian_reverse, but that use is likely to be replace by a
// more tailored floating-point implementation.
template <class T>
inline T std_reverse_endianness(T x) BOOST_NOEXCEPT
inline T std_endian_reverse(T x) BOOST_NOEXCEPT
{
T tmp(x);
std::reverse(
@@ -196,12 +196,12 @@ namespace endian
// //
//--------------------------------------------------------------------------------------//
inline int8_t reverse_endianness(int8_t x) BOOST_NOEXCEPT
inline int8_t endian_reverse(int8_t x) BOOST_NOEXCEPT
{
return x;
}
inline int16_t reverse_endianness(int16_t x) BOOST_NOEXCEPT
inline int16_t endian_reverse(int16_t x) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_NO_INTRINSICS
return (static_cast<uint16_t>(x) << 8)
@@ -211,7 +211,7 @@ namespace endian
# endif
}
inline int32_t reverse_endianness(int32_t x) BOOST_NOEXCEPT
inline int32_t endian_reverse(int32_t x) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_NO_INTRINSICS
uint32_t step16;
@@ -224,7 +224,7 @@ namespace endian
# endif
}
inline int64_t reverse_endianness(int64_t x) BOOST_NOEXCEPT
inline int64_t endian_reverse(int64_t x) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_NO_INTRINSICS
uint64_t step32, step16;
@@ -238,12 +238,12 @@ namespace endian
# endif
}
inline uint8_t reverse_endianness(uint8_t x) BOOST_NOEXCEPT
inline uint8_t endian_reverse(uint8_t x) BOOST_NOEXCEPT
{
return x;
}
inline uint16_t reverse_endianness(uint16_t x) BOOST_NOEXCEPT
inline uint16_t endian_reverse(uint16_t x) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_NO_INTRINSICS
return (x << 8)
@@ -253,7 +253,7 @@ namespace endian
# endif
}
inline uint32_t reverse_endianness(uint32_t x) BOOST_NOEXCEPT
inline uint32_t endian_reverse(uint32_t x) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_NO_INTRINSICS
uint32_t step16;
@@ -266,7 +266,7 @@ namespace endian
# endif
}
inline uint64_t reverse_endianness(uint64_t x) BOOST_NOEXCEPT
inline uint64_t endian_reverse(uint64_t x) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_NO_INTRINSICS
uint64_t step32, step16;
@@ -280,20 +280,20 @@ namespace endian
# endif
}
inline float reverse_endianness(float x) BOOST_NOEXCEPT
inline float endian_reverse(float x) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(sizeof(float) == sizeof(uint32_t),
"boost::endian currently supports only sizeof(float) == 4;"
" please report static_assert failure to the boost mailing list");
return detail::std_reverse_endianness(x);
return detail::std_endian_reverse(x);
}
inline double reverse_endianness(double x) BOOST_NOEXCEPT
inline double endian_reverse(double x) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(sizeof(double) == sizeof(uint64_t),
"boost::endian currently supports only sizeof(double) == 8;"
" please report static_assert failure to the boost mailing list");
return detail::std_reverse_endianness(x);
return detail::std_endian_reverse(x);
}
template <class Reversible >
@@ -302,7 +302,7 @@ namespace endian
# ifdef BOOST_BIG_ENDIAN
return x;
# else
return reverse_endianness(x);
return endian_reverse(x);
# endif
}
@@ -312,7 +312,7 @@ namespace endian
# ifdef BOOST_BIG_ENDIAN
return x;
# else
return reverse_endianness(x);
return endian_reverse(x);
# endif
}
@@ -322,7 +322,7 @@ namespace endian
# ifdef BOOST_LITTLE_ENDIAN
return x;
# else
return reverse_endianness(x);
return endian_reverse(x);
# endif
}
@@ -332,14 +332,14 @@ namespace endian
# ifdef BOOST_LITTLE_ENDIAN
return x;
# else
return reverse_endianness(x);
return endian_reverse(x);
# endif
}
namespace detail
{
// Primary template and specializations to support reverse_endianness().
// See rationale in reverse_endianness() below.
// Primary template and specializations to support endian_reverse().
// See rationale in endian_reverse() below.
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible>
class value_converter ; // primary template
template <class T> class value_converter <order::big, order::big, T>
@@ -347,9 +347,9 @@ namespace endian
template <class T> class value_converter <order::little, order::little, T>
{public: T operator()(T x) BOOST_NOEXCEPT {return x;}};
template <class T> class value_converter <order::big, order::little, T>
{public: T operator()(T x) BOOST_NOEXCEPT {return reverse_endianness(x);}};
{public: T operator()(T x) BOOST_NOEXCEPT {return endian_reverse(x);}};
template <class T> class value_converter <order::little, order::big, T>
{public: T operator()(T x) BOOST_NOEXCEPT {return reverse_endianness(x);}};
{public: T operator()(T x) BOOST_NOEXCEPT {return endian_reverse(x);}};
}
// generic conditional reverse
@@ -367,7 +367,7 @@ namespace endian
inline Reversible runtime_conditional_reverse(Reversible from,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT
{
return from_order == to_order ? from : reverse_endianness(from);
return from_order == to_order ? from : endian_reverse(from);
}
//--------------------------------------------------------------------------------------//
@@ -376,9 +376,9 @@ namespace endian
// reverse in place
template <class Value>
inline void reverse_endianness_in_place(Value& x) BOOST_NOEXCEPT
inline void endian_reverse_in_place(Value& x) BOOST_NOEXCEPT
{
x = reverse_endianness(x);
x = endian_reverse(x);
}
template <class Reversible>
@@ -386,7 +386,7 @@ namespace endian
inline void big_to_native_in_place(Reversible&) BOOST_NOEXCEPT {}
# else
inline void big_to_native_in_place(Reversible& x) BOOST_NOEXCEPT
{ reverse_endianness_in_place(x); }
{ endian_reverse_in_place(x); }
# endif
template <class Reversible>
# ifdef BOOST_BIG_ENDIAN
@@ -394,7 +394,7 @@ namespace endian
# else
inline void native_to_big_in_place(Reversible& x) BOOST_NOEXCEPT
{
reverse_endianness_in_place(x);
endian_reverse_in_place(x);
}
# endif
@@ -403,7 +403,7 @@ namespace endian
inline void little_to_native_in_place(Reversible&) BOOST_NOEXCEPT {}
# else
inline void little_to_native_in_place(Reversible& x) BOOST_NOEXCEPT
{ reverse_endianness_in_place(x); }
{ endian_reverse_in_place(x); }
# endif
template <class Reversible>
# ifdef BOOST_LITTLE_ENDIAN
@@ -411,15 +411,15 @@ namespace endian
# else
inline void native_to_little_in_place(Reversible& x) BOOST_NOEXCEPT
{
reverse_endianness_in_place(x);
endian_reverse_in_place(x);
}
# endif
namespace detail
{
// Primary template and specializations support generic
// reverse_endianness_in_place().
// See rationale in reverse_endianness_in_place() below.
// endian_reverse_in_place().
// See rationale in endian_reverse_in_place() below.
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class Reversible>
class converter; // primary template
template <class T> class converter<order::big, order::big, T>
@@ -427,9 +427,9 @@ namespace endian
template <class T> class converter<order::little, order::little, T>
{public: void operator()(T&) BOOST_NOEXCEPT {/*no effect*/}};
template <class T> class converter<order::big, order::little, T>
{public: void operator()(T& x) BOOST_NOEXCEPT { reverse_endianness_in_place(x); }};
{public: void operator()(T& x) BOOST_NOEXCEPT { endian_reverse_in_place(x); }};
template <class T> class converter<order::little, order::big, T>
{public: void operator()(T& x) BOOST_NOEXCEPT { reverse_endianness_in_place(x); }};
{public: void operator()(T& x) BOOST_NOEXCEPT { endian_reverse_in_place(x); }};
} // namespace detail
// generic conditional reverse in place
@@ -450,7 +450,7 @@ namespace endian
BOOST_NOEXCEPT
{
if (from_order != to_order)
reverse_endianness_in_place(x);
endian_reverse_in_place(x);
}

View File

@@ -139,17 +139,17 @@ namespace
# ifdef BOOST_BIG_ENDIAN
BOOST_TEST_EQ(native, big);
BOOST_TEST_EQ(be::detail::std_reverse_endianness(native), little);
BOOST_TEST_EQ(be::detail::std_endian_reverse(native), little);
# else
BOOST_TEST_EQ(be::detail::std_reverse_endianness(native), big);
BOOST_TEST_EQ(be::detail::std_endian_reverse(native), big);
BOOST_TEST_EQ(native, little);
# endif
// value-by-value tests
// unconditional reverse
BOOST_TEST_EQ(be::reverse_endianness(big), little);
BOOST_TEST_EQ(be::reverse_endianness(little), big);
BOOST_TEST_EQ(be::endian_reverse(big), little);
BOOST_TEST_EQ(be::endian_reverse(little), big);
// conditional reverse
BOOST_TEST_EQ(be::native_to_big(native), big);
@@ -201,8 +201,8 @@ namespace
T x;
// unconditional reverse
x = big; be::reverse_endianness_in_place(x); BOOST_TEST_EQ(x, little);
x = little; be::reverse_endianness_in_place(x); BOOST_TEST_EQ(x, big);
x = big; be::endian_reverse_in_place(x); BOOST_TEST_EQ(x, little);
x = little; be::endian_reverse_in_place(x); BOOST_TEST_EQ(x, big);
// conditional reverse
x = native; be::native_to_big_in_place(x); BOOST_TEST_EQ(x, big);
@@ -279,14 +279,14 @@ namespace
udt.member3 = native;
tmp = be::conditional_reverse<be::order::big, be::order::little>(udt);
BOOST_TEST_EQ(tmp.member1, be::reverse_endianness(big));
BOOST_TEST_EQ(tmp.member2, be::reverse_endianness(little));
BOOST_TEST_EQ(tmp.member3, be::reverse_endianness(native));
BOOST_TEST_EQ(tmp.member1, be::endian_reverse(big));
BOOST_TEST_EQ(tmp.member2, be::endian_reverse(little));
BOOST_TEST_EQ(tmp.member3, be::endian_reverse(native));
be::conditional_reverse_in_place<be::order::big, be::order::little>(udt);
BOOST_TEST_EQ(udt.member1, be::reverse_endianness(big));
BOOST_TEST_EQ(udt.member2, be::reverse_endianness(little));
BOOST_TEST_EQ(udt.member3, be::reverse_endianness(native));
BOOST_TEST_EQ(udt.member1, be::endian_reverse(big));
BOOST_TEST_EQ(udt.member2, be::endian_reverse(little));
BOOST_TEST_EQ(udt.member3, be::endian_reverse(native));
udt.member1 = big;
udt.member2 = little;
@@ -311,7 +311,7 @@ namespace
namespace user
{
// UDT1 supplies both reverse_endianness and reverse_endianness_in_place
// UDT1 supplies both endian_reverse and endian_reverse_in_place
struct UDT1
{
int64_t member1;
@@ -319,23 +319,23 @@ namespace
int64_t member3;
};
UDT1 reverse_endianness(const UDT1& udt) BOOST_NOEXCEPT
UDT1 endian_reverse(const UDT1& udt) BOOST_NOEXCEPT
{
UDT1 tmp;
tmp.member1 = boost::endian::reverse_endianness(udt.member1);
tmp.member2 = boost::endian::reverse_endianness(udt.member2);
tmp.member3 = boost::endian::reverse_endianness(udt.member3);
tmp.member1 = boost::endian::endian_reverse(udt.member1);
tmp.member2 = boost::endian::endian_reverse(udt.member2);
tmp.member3 = boost::endian::endian_reverse(udt.member3);
return tmp;
}
void reverse_endianness_in_place(UDT1& udt) BOOST_NOEXCEPT
void endian_reverse_in_place(UDT1& udt) BOOST_NOEXCEPT
{
boost::endian::reverse_endianness_in_place(udt.member1);
boost::endian::reverse_endianness_in_place(udt.member2);
boost::endian::reverse_endianness_in_place(udt.member3);
boost::endian::endian_reverse_in_place(udt.member1);
boost::endian::endian_reverse_in_place(udt.member2);
boost::endian::endian_reverse_in_place(udt.member3);
}
// UDT2 supplies only reverse_endianness
// UDT2 supplies only endian_reverse
struct UDT2
{
int64_t member1;
@@ -343,16 +343,16 @@ namespace
int64_t member3;
};
UDT2 reverse_endianness(const UDT2& udt) BOOST_NOEXCEPT
UDT2 endian_reverse(const UDT2& udt) BOOST_NOEXCEPT
{
UDT2 tmp;
tmp.member1 = boost::endian::reverse_endianness(udt.member1);
tmp.member2 = boost::endian::reverse_endianness(udt.member2);
tmp.member3 = boost::endian::reverse_endianness(udt.member3);
tmp.member1 = boost::endian::endian_reverse(udt.member1);
tmp.member2 = boost::endian::endian_reverse(udt.member2);
tmp.member3 = boost::endian::endian_reverse(udt.member3);
return tmp;
}
// UDT3 supplies neither reverse_endianness nor reverse_endianness_in_place,
// UDT3 supplies neither endian_reverse nor endian_reverse_in_place,
// so udt_test<UDT3>() should fail to compile
struct UDT3
{
@@ -404,7 +404,7 @@ int cpp_main(int, char * [])
#ifdef BOOST_ENDIAN_COMPILE_FAIL
cout << "UDT 3" << endl;
udt_test<user::UDT3>(); // should fail to compile since has not reverse_endianness()
udt_test<user::UDT3>(); // should fail to compile since has not endian_reverse()
#endif
return ::boost::report_errors();

View File

@@ -29,6 +29,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uses_cases", "uses_cases\us
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "conversion_use_case", "conversion_use_case\conversion_use_case.vcxproj", "{1139E765-DE0F-497A-A7D9-EB2683521DF1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "html", "html\html.vcxproj", "{3E0B428D-FDBB-40AF-ACA8-DE677B88D39C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -130,6 +132,12 @@ Global
{1139E765-DE0F-497A-A7D9-EB2683521DF1}.Release|Win32.ActiveCfg = Release|Win32
{1139E765-DE0F-497A-A7D9-EB2683521DF1}.Release|Win32.Build.0 = Release|Win32
{1139E765-DE0F-497A-A7D9-EB2683521DF1}.Release|x64.ActiveCfg = Release|Win32
{3E0B428D-FDBB-40AF-ACA8-DE677B88D39C}.Debug|Win32.ActiveCfg = Debug|Win32
{3E0B428D-FDBB-40AF-ACA8-DE677B88D39C}.Debug|Win32.Build.0 = Debug|Win32
{3E0B428D-FDBB-40AF-ACA8-DE677B88D39C}.Debug|x64.ActiveCfg = Debug|Win32
{3E0B428D-FDBB-40AF-ACA8-DE677B88D39C}.Release|Win32.ActiveCfg = Release|Win32
{3E0B428D-FDBB-40AF-ACA8-DE677B88D39C}.Release|Win32.Build.0 = Release|Win32
{3E0B428D-FDBB-40AF-ACA8-DE677B88D39C}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE