Change "in_place" to "inplace". Rationale: shortens names without impacting expressiveness.

This commit is contained in:
Beman
2014-12-10 09:39:03 -05:00
parent 2cbcd6f7d3
commit c201455c84
10 changed files with 134 additions and 132 deletions

View File

@@ -6,9 +6,11 @@ return-by-value modify-argument
reverse_endianness reverse_endianness_in_place reverse_endianness reverse_endianness_in_place
" reverse_endianness_arg " reverse_endianness_arg
endian_reverse endian_reverse_in_place endian_reverse endian_reverse_in_place
" endian_reverse_inplace
" endian_reverse_replace
" endian_reverse_in_situ " endian_reverse_in_situ
" endian_reverse_here " endian_reverse_here
" endian_reverse_this <----- " endian_reverse_this
" endian_reverse_self " endian_reverse_self
" endian_reverse_arg " endian_reverse_arg
" endian_reverse_in " endian_reverse_in

View File

@@ -122,20 +122,20 @@ namespace endian
order order1, order order2) noexcept; order order1, order order2) noexcept;
template &lt;class Reversible&gt; template &lt;class Reversible&gt;
void endian_reverse_in_place(Reversible&amp; x) noexcept; void endian_reverse_inplace(Reversible&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class Reversible&gt;
void big_to_native_in_place(Reversible&amp; x) noexcept; void big_to_native_inplace(Reversible&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class Reversible&gt;
void native_to_big_in_place(Reversible&amp; x) noexcept; void native_to_big_inplace(Reversible&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class Reversible&gt;
void little_to_native_in_place(Reversible&amp; x) noexcept; void little_to_native_inplace(Reversible&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class Reversible&gt;
void native_to_little_in_place(Reversible&amp; x) noexcept; void native_to_little_inplace(Reversible&amp; x) noexcept;
template &lt;order O1, order O2, class Reversible&gt; template &lt;order O1, order O2, class Reversible&gt;
void conditional_reverse_in_place(Reversible&amp; x) noexcept; void conditional_reverse_inplace(Reversible&amp; x) noexcept;
template &lt;class Reversible&gt; template &lt;class Reversible&gt;
void conditional_reverse_in_place(Reversible&amp; x, void conditional_reverse_inplace(Reversible&amp; x,
order order1, order order2) noexcept; order order1, order order2) noexcept;
} // namespace endian } // namespace endian
@@ -170,7 +170,7 @@ instantiating a template.</p>
</tr> </tr>
<tr> <tr>
<td valign="top"> <td valign="top">
<code>endian_reverse_in_place(x)</code></td> <code>endian_reverse_inplace(x)</code></td>
<td valign="top"> <td valign="top">
<code>x</code> is a <code>x</code> is a
modifiable lvalue of type <code>Reversible</code>.</td> 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 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> 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_in_place</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>Reversible</code>
requirements. User-defined types may provide <code>endian_reverse_in_place</code> requirements. User-defined types may provide <code>endian_reverse_inplace</code>
for improved efficiency. <i>&mdash;end note</i>]</p> for improved efficiency. <i>&mdash;end note</i>]</p>
<p> <span style="background-color: #FFFF00">This still isn&#39;t right. There are <p> <span style="background-color: #FFFF00">This still isn&#39;t right. There are
@@ -212,8 +212,8 @@ call to <code>endian_reverse(<i>argument</i>)</code>, as described in the
preceding table.</p> preceding table.</p>
<p> The endianness reversal function templates that modify their argument in <p> The endianness reversal function templates that modify their argument in
place, except <code>endian_reverse_in_place</code> itself, are required to perform reversal of endianness if needed by making an place, except <code>endian_reverse_inplace</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>, unqualified call to <code>endian_reverse_inplace(<i>argument</i>)</code>,
as described in the preceding table.</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">
@@ -273,53 +273,53 @@ Reversible conditional_reverse(Reversible x,
</blockquote> </blockquote>
<pre>template &lt;class Reversible&gt; <pre>template &lt;class Reversible&gt;
void endian_reverse_in_place(Reversible&amp; x) noexcept; </pre> void endian_reverse_inplace(Reversible&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 Reversible&gt;
void big_to_native_in_place(Reversible&amp; x) noexcept; </pre> void big_to_native_inplace(Reversible&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_in_place&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 Reversible&gt;
void native_to_big_in_place(Reversible&amp; x) noexcept; </pre> void native_to_big_inplace(Reversible&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_in_place&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 Reversible&gt;
void little_to_native_in_place(Reversible&amp; x) noexcept; </pre> void little_to_native_inplace(Reversible&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_in_place&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 Reversible&gt;
void native_to_little_in_place(Reversible&amp; x) noexcept; </pre> void native_to_little_inplace(Reversible&amp; x) noexcept; </pre>
<blockquote> <blockquote>
<p> <p>
<i>Effects:</i> <code>conditional_reverse_in_place&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 Reversible&gt;
void conditional_reverse_in_place(Reversible&amp; x) noexcept; </pre> void conditional_reverse_inplace(Reversible&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_in_place(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 Reversible&gt;
void conditional_reverse_in_place(Reversible&amp; x, void conditional_reverse_inplace(Reversible&amp; x,
order order1, order order2) noexcept; </pre> order order1, order order2) noexcept; </pre>
<blockquote> <blockquote>
<p><i>Effects: </i>If <code>order1 == order2</code> then <code>endian_reverse_in_place(x)</code>.</p> <p><i>Effects: </i>If <code>order1 == order2</code> then <code>endian_reverse_inplace(x)</code>.</p>
</blockquote> </blockquote>

View File

@@ -42,7 +42,7 @@ namespace user
desc_[sizeof(desc_-1)] = '\0'; desc_[sizeof(desc_-1)] = '\0';
} }
friend void endian_reverse_in_place(UDT&); friend void endian_reverse_inplace(UDT&);
private: private:
int32_t id_; int32_t id_;
@@ -50,10 +50,10 @@ namespace user
char desc_[56]; // '/0' char desc_[56]; // '/0'
}; };
void endian_reverse_in_place(UDT& x) void endian_reverse_inplace(UDT& x)
{ {
boost::endian::endian_reverse_in_place(x.id_); boost::endian::endian_reverse_inplace(x.id_);
boost::endian::endian_reverse_in_place(x.value_); boost::endian::endian_reverse_inplace(x.value_);
} }
} }
@@ -64,16 +64,16 @@ int main(int, char* [])
//cout << std::hex; //cout << std::hex;
cout << "(1) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; cout << "(1) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
user::endian_reverse_in_place(x); user::endian_reverse_inplace(x);
cout << "(2) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; cout << "(2) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
endian_reverse_in_place(x); endian_reverse_inplace(x);
cout << "(3) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; cout << "(3) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
conditional_reverse_in_place<order::little, order::big>(x); conditional_reverse_inplace<order::little, order::big>(x);
cout << "(4) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; cout << "(4) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
conditional_reverse_in_place(x, order::big, order::little); conditional_reverse_inplace(x, order::big, order::little);
cout << "(5) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; cout << "(5) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
} }

View File

@@ -113,9 +113,9 @@ namespace endian
// user-defined types (UDTs) // // user-defined types (UDTs) //
// // // //
// All reverse in place function templates are required to be implemented in terms // // All reverse in place function templates are required to be implemented in terms //
// of an unqualified call to "endian_reverse_in_place(x)", a function reversing // // of an unqualified call to "endian_reverse_inplace(x)", a function reversing //
// the endianness of x, which is a non-const reference. This provides a // // 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 // // customization point for any UDT that provides a "reverse_inplace" free-function //
// meeting the requirements. The free-function must be declared in the same // // meeting the requirements. The free-function must be declared in the same //
// namespace as the UDT itself so that it will be found by argument-dependent // // namespace as the UDT itself so that it will be found by argument-dependent //
// lookup (ADL). // // lookup (ADL). //
@@ -124,32 +124,32 @@ namespace endian
// reverse in place // reverse in place
template <class Value> template <class Value>
inline void endian_reverse_in_place(Value& x) BOOST_NOEXCEPT; inline void endian_reverse_inplace(Value& 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 Reversible>
inline void big_to_native_in_place(Reversible& x) BOOST_NOEXCEPT; inline void big_to_native_inplace(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise endian_reverse_in_place(x) // Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x)
template <class Reversible> template <class Reversible>
inline void native_to_big_in_place(Reversible& x) BOOST_NOEXCEPT; inline void native_to_big_inplace(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is big, otherwise endian_reverse_in_place(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 Reversible>
inline void little_to_native_in_place(Reversible& x) BOOST_NOEXCEPT; inline void little_to_native_inplace(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise endian_reverse_in_place(x); // Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x);
template <class Reversible> template <class Reversible>
inline void native_to_little_in_place(Reversible& x) BOOST_NOEXCEPT; inline void native_to_little_inplace(Reversible& x) BOOST_NOEXCEPT;
// Effects: none if native byte-order is little, otherwise endian_reverse_in_place(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 Reversible>
inline void conditional_reverse_in_place(Reversible& x) BOOST_NOEXCEPT; inline void conditional_reverse_inplace(Reversible& x) BOOST_NOEXCEPT;
// runtime reverse in place // runtime reverse in place
template <class Reversible> template <class Reversible>
inline void conditional_reverse_in_place(Reversible& x, inline void conditional_reverse_inplace(Reversible& 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;
@@ -376,50 +376,50 @@ namespace endian
// reverse in place // reverse in place
template <class Value> template <class Value>
inline void endian_reverse_in_place(Value& x) BOOST_NOEXCEPT inline void endian_reverse_inplace(Value& x) BOOST_NOEXCEPT
{ {
x = endian_reverse(x); x = endian_reverse(x);
} }
template <class Reversible> template <class Reversible>
# ifdef BOOST_BIG_ENDIAN # ifdef BOOST_BIG_ENDIAN
inline void big_to_native_in_place(Reversible&) BOOST_NOEXCEPT {} inline void big_to_native_inplace(Reversible&) BOOST_NOEXCEPT {}
# else # else
inline void big_to_native_in_place(Reversible& x) BOOST_NOEXCEPT inline void big_to_native_inplace(Reversible& x) BOOST_NOEXCEPT
{ endian_reverse_in_place(x); } { endian_reverse_inplace(x); }
# endif # endif
template <class Reversible> template <class Reversible>
# ifdef BOOST_BIG_ENDIAN # ifdef BOOST_BIG_ENDIAN
inline void native_to_big_in_place(Reversible&) BOOST_NOEXCEPT {} inline void native_to_big_inplace(Reversible&) BOOST_NOEXCEPT {}
# else # else
inline void native_to_big_in_place(Reversible& x) BOOST_NOEXCEPT inline void native_to_big_inplace(Reversible& x) BOOST_NOEXCEPT
{ {
endian_reverse_in_place(x); endian_reverse_inplace(x);
} }
# endif # endif
template <class Reversible> template <class Reversible>
# ifdef BOOST_LITTLE_ENDIAN # ifdef BOOST_LITTLE_ENDIAN
inline void little_to_native_in_place(Reversible&) BOOST_NOEXCEPT {} inline void little_to_native_inplace(Reversible&) BOOST_NOEXCEPT {}
# else # else
inline void little_to_native_in_place(Reversible& x) BOOST_NOEXCEPT inline void little_to_native_inplace(Reversible& x) BOOST_NOEXCEPT
{ endian_reverse_in_place(x); } { endian_reverse_inplace(x); }
# endif # endif
template <class Reversible> template <class Reversible>
# ifdef BOOST_LITTLE_ENDIAN # ifdef BOOST_LITTLE_ENDIAN
inline void native_to_little_in_place(Reversible&) BOOST_NOEXCEPT {} inline void native_to_little_inplace(Reversible&) BOOST_NOEXCEPT {}
# else # else
inline void native_to_little_in_place(Reversible& x) BOOST_NOEXCEPT inline void native_to_little_inplace(Reversible& x) BOOST_NOEXCEPT
{ {
endian_reverse_in_place(x); endian_reverse_inplace(x);
} }
# endif # endif
namespace detail namespace detail
{ {
// Primary template and specializations support generic // Primary template and specializations support generic
// endian_reverse_in_place(). // endian_reverse_inplace().
// See rationale in endian_reverse_in_place() 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 Reversible>
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>
@@ -427,14 +427,14 @@ namespace endian
template <class T> class converter<order::little, order::little, T> template <class T> class converter<order::little, order::little, T>
{public: void operator()(T&) BOOST_NOEXCEPT {/*no effect*/}}; {public: void operator()(T&) BOOST_NOEXCEPT {/*no effect*/}};
template <class T> class converter<order::big, order::little, T> template <class T> class converter<order::big, order::little, T>
{public: void operator()(T& x) BOOST_NOEXCEPT { endian_reverse_in_place(x); }}; {public: void operator()(T& x) BOOST_NOEXCEPT { endian_reverse_inplace(x); }};
template <class T> class converter<order::little, order::big, T> template <class T> class converter<order::little, order::big, T>
{public: void operator()(T& x) BOOST_NOEXCEPT { endian_reverse_in_place(x); }}; {public: void operator()(T& x) BOOST_NOEXCEPT { endian_reverse_inplace(x); }};
} // 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 Reversible>
inline void conditional_reverse_in_place(Reversible& x) BOOST_NOEXCEPT inline void conditional_reverse_inplace(Reversible& 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
@@ -445,12 +445,12 @@ namespace endian
// runtime reverse in place // runtime reverse in place
template <class Reversible> template <class Reversible>
inline void conditional_reverse_in_place(Reversible& x, inline void conditional_reverse_inplace(Reversible& 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
{ {
if (from_order != to_order) if (from_order != to_order)
endian_reverse_in_place(x); endian_reverse_inplace(x);
} }

View File

@@ -120,7 +120,7 @@ namespace
} }
} }
inline void in_place(int32_t& x) inline void inplace(int32_t& x)
{ {
x = (static_cast<uint32_t>(x) << 24) x = (static_cast<uint32_t>(x) << 24)
| ((static_cast<uint32_t>(x) << 8) & 0x00ff0000) | ((static_cast<uint32_t>(x) << 8) & 0x00ff0000)
@@ -162,10 +162,10 @@ namespace
return v; return v;
} }
inline int32_t modify_in_place(int32_t x) inline int32_t modify_inplace(int32_t x)
{ {
int32_t v(x); int32_t v(x);
in_place(v); inplace(v);
return v; return v;
} }
@@ -214,7 +214,7 @@ int main(int argc, char * argv[])
#ifndef BOOST_TWO_ARG #ifndef BOOST_TWO_ARG
overhead = benchmark(modify_noop, "modify no-op"); overhead = benchmark(modify_noop, "modify no-op");
benchmark(modify_in_place, "modify in place"/*, overhead*/); benchmark(modify_inplace, "modify in place"/*, overhead*/);
benchmark(modify_by_return, "modify by return"/*, overhead*/); benchmark(modify_by_return, "modify by return"/*, overhead*/);
benchmark(modify_by_return_pyry, "modify by return_pyry"/*, overhead*/); benchmark(modify_by_return_pyry, "modify by return_pyry"/*, overhead*/);
benchmark(modify_by_return_intrinsic, "modify by return_intrinsic"/*, overhead*/); benchmark(modify_by_return_intrinsic, "modify by return_intrinsic"/*, overhead*/);

View File

@@ -201,62 +201,62 @@ namespace
T x; T x;
// unconditional reverse // unconditional reverse
x = big; be::endian_reverse_in_place(x); BOOST_TEST_EQ(x, little); x = big; be::endian_reverse_inplace(x); BOOST_TEST_EQ(x, little);
x = little; be::endian_reverse_in_place(x); BOOST_TEST_EQ(x, big); x = little; be::endian_reverse_inplace(x); BOOST_TEST_EQ(x, big);
// conditional reverse // conditional reverse
x = native; be::native_to_big_in_place(x); BOOST_TEST_EQ(x, big); x = native; be::native_to_big_inplace(x); BOOST_TEST_EQ(x, big);
x = native; be::native_to_little_in_place(x); BOOST_TEST_EQ(x, little); x = native; be::native_to_little_inplace(x); BOOST_TEST_EQ(x, little);
x = big; be::big_to_native_in_place(x); BOOST_TEST_EQ(x, native); x = big; be::big_to_native_inplace(x); BOOST_TEST_EQ(x, native);
x = little; be::little_to_native_in_place(x); BOOST_TEST_EQ(x, native); x = little; be::little_to_native_inplace(x); BOOST_TEST_EQ(x, native);
// generic conditional reverse // generic conditional reverse
x = big; be::conditional_reverse_in_place<be::order::big, be::order::big>(x); x = big; be::conditional_reverse_inplace<be::order::big, be::order::big>(x);
BOOST_TEST_EQ(x, big); BOOST_TEST_EQ(x, big);
x = little; be::conditional_reverse_in_place<be::order::little, be::order::little>(x); x = little; be::conditional_reverse_inplace<be::order::little, be::order::little>(x);
BOOST_TEST_EQ(x, little); BOOST_TEST_EQ(x, little);
x = native; be::conditional_reverse_in_place<be::order::native, be::order::native>(x); x = native; be::conditional_reverse_inplace<be::order::native, be::order::native>(x);
BOOST_TEST_EQ(x, native); BOOST_TEST_EQ(x, native);
x = big; be::conditional_reverse_in_place<be::order::big, be::order::little>(x); x = big; be::conditional_reverse_inplace<be::order::big, be::order::little>(x);
BOOST_TEST_EQ(x, little); BOOST_TEST_EQ(x, little);
x = big; be::conditional_reverse_in_place<be::order::big, be::order::native>(x); x = big; be::conditional_reverse_inplace<be::order::big, be::order::native>(x);
BOOST_TEST_EQ(x, native); BOOST_TEST_EQ(x, native);
x = little; be::conditional_reverse_in_place<be::order::little, be::order::big>(x); x = little; be::conditional_reverse_inplace<be::order::little, be::order::big>(x);
BOOST_TEST_EQ(x, big); BOOST_TEST_EQ(x, big);
x = little; be::conditional_reverse_in_place<be::order::little, be::order::native>(x); x = little; be::conditional_reverse_inplace<be::order::little, be::order::native>(x);
BOOST_TEST_EQ(x, native); BOOST_TEST_EQ(x, native);
x = native; be::conditional_reverse_in_place<be::order::native, be::order::big>(x); x = native; be::conditional_reverse_inplace<be::order::native, be::order::big>(x);
BOOST_TEST_EQ(x, big); BOOST_TEST_EQ(x, big);
x = native; be::conditional_reverse_in_place<be::order::native, be::order::little>(x); x = native; be::conditional_reverse_inplace<be::order::native, be::order::little>(x);
BOOST_TEST_EQ(x, little); BOOST_TEST_EQ(x, little);
// runtime conditional reverse // runtime conditional reverse
x = big; x = big;
be::conditional_reverse_in_place(x, be::order::big, be::order::big); be::conditional_reverse_inplace(x, be::order::big, be::order::big);
BOOST_TEST_EQ(x, big); BOOST_TEST_EQ(x, big);
x = little; x = little;
be::conditional_reverse_in_place(x, be::order::little, be::order::little); be::conditional_reverse_inplace(x, be::order::little, be::order::little);
BOOST_TEST_EQ(x, little); BOOST_TEST_EQ(x, little);
x = native; x = native;
be::conditional_reverse_in_place(x, be::order::native, be::order::native); be::conditional_reverse_inplace(x, be::order::native, be::order::native);
BOOST_TEST_EQ(x, native); BOOST_TEST_EQ(x, native);
x = big; x = big;
be::conditional_reverse_in_place(x, be::order::big, be::order::little); be::conditional_reverse_inplace(x, be::order::big, be::order::little);
BOOST_TEST_EQ(x, little); BOOST_TEST_EQ(x, little);
x = big; x = big;
be::conditional_reverse_in_place(x, be::order::big, be::order::native); be::conditional_reverse_inplace(x, be::order::big, be::order::native);
BOOST_TEST_EQ(x, native); BOOST_TEST_EQ(x, native);
x = little; x = little;
be::conditional_reverse_in_place(x, be::order::little, be::order::big); be::conditional_reverse_inplace(x, be::order::little, be::order::big);
BOOST_TEST_EQ(x, big); BOOST_TEST_EQ(x, big);
x = little; x = little;
be::conditional_reverse_in_place(x, be::order::little, be::order::native); be::conditional_reverse_inplace(x, be::order::little, be::order::native);
BOOST_TEST_EQ(x, native); BOOST_TEST_EQ(x, native);
x = native; x = native;
be::conditional_reverse_in_place(x, be::order::native, be::order::big); be::conditional_reverse_inplace(x, be::order::native, be::order::big);
BOOST_TEST_EQ(x, big); BOOST_TEST_EQ(x, big);
x = native; x = native;
be::conditional_reverse_in_place(x, be::order::native, be::order::little); be::conditional_reverse_inplace(x, be::order::native, be::order::little);
BOOST_TEST_EQ(x, little); BOOST_TEST_EQ(x, little);
} }
@@ -283,7 +283,7 @@ namespace
BOOST_TEST_EQ(tmp.member2, be::endian_reverse(little)); BOOST_TEST_EQ(tmp.member2, be::endian_reverse(little));
BOOST_TEST_EQ(tmp.member3, be::endian_reverse(native)); BOOST_TEST_EQ(tmp.member3, be::endian_reverse(native));
be::conditional_reverse_in_place<be::order::big, be::order::little>(udt); be::conditional_reverse_inplace<be::order::big, be::order::little>(udt);
BOOST_TEST_EQ(udt.member1, be::endian_reverse(big)); BOOST_TEST_EQ(udt.member1, be::endian_reverse(big));
BOOST_TEST_EQ(udt.member2, be::endian_reverse(little)); BOOST_TEST_EQ(udt.member2, be::endian_reverse(little));
BOOST_TEST_EQ(udt.member3, be::endian_reverse(native)); BOOST_TEST_EQ(udt.member3, be::endian_reverse(native));
@@ -298,7 +298,7 @@ namespace
BOOST_TEST_EQ(tmp.member2, little); BOOST_TEST_EQ(tmp.member2, little);
BOOST_TEST_EQ(tmp.member3, native); BOOST_TEST_EQ(tmp.member3, native);
be::conditional_reverse_in_place<be::order::big, be::order::big>(udt); be::conditional_reverse_inplace<be::order::big, be::order::big>(udt);
BOOST_TEST_EQ(udt.member1, big); BOOST_TEST_EQ(udt.member1, big);
BOOST_TEST_EQ(udt.member2, little); BOOST_TEST_EQ(udt.member2, little);
BOOST_TEST_EQ(udt.member3, native); BOOST_TEST_EQ(udt.member3, native);
@@ -311,7 +311,7 @@ namespace
namespace user namespace user
{ {
// UDT1 supplies both endian_reverse and endian_reverse_in_place // UDT1 supplies both endian_reverse and endian_reverse_inplace
struct UDT1 struct UDT1
{ {
int64_t member1; int64_t member1;
@@ -328,11 +328,11 @@ namespace
return tmp; return tmp;
} }
void endian_reverse_in_place(UDT1& udt) BOOST_NOEXCEPT void endian_reverse_inplace(UDT1& udt) BOOST_NOEXCEPT
{ {
boost::endian::endian_reverse_in_place(udt.member1); boost::endian::endian_reverse_inplace(udt.member1);
boost::endian::endian_reverse_in_place(udt.member2); boost::endian::endian_reverse_inplace(udt.member2);
boost::endian::endian_reverse_in_place(udt.member3); boost::endian::endian_reverse_inplace(udt.member3);
} }
// UDT2 supplies only endian_reverse // UDT2 supplies only endian_reverse
@@ -352,7 +352,7 @@ namespace
return tmp; return tmp;
} }
// UDT3 supplies neither endian_reverse nor endian_reverse_in_place, // UDT3 supplies neither endian_reverse nor endian_reverse_inplace,
// so udt_test<UDT3>() should fail to compile // so udt_test<UDT3>() should fail to compile
struct UDT3 struct UDT3
{ {

View File

@@ -604,25 +604,25 @@ namespace
{ {
// aligned floating point types // aligned floating point types
float big_float32_expected = (std::numeric_limits<float>::max) (); float big_float32_expected = (std::numeric_limits<float>::max) ();
boost::endian::native_to_big_in_place(big_float32_expected); boost::endian::native_to_big_inplace(big_float32_expected);
big_float32_t big_float32((std::numeric_limits<float>::max) ()); big_float32_t big_float32((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(big_float32.data(), VERIFY(std::memcmp(big_float32.data(),
reinterpret_cast<const char*>(&big_float32_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&big_float32_expected), sizeof(float)) == 0);
float little_float32_expected = (std::numeric_limits<float>::max) (); float little_float32_expected = (std::numeric_limits<float>::max) ();
boost::endian::native_to_little_in_place(little_float32_expected); boost::endian::native_to_little_inplace(little_float32_expected);
little_float32_t little_float32((std::numeric_limits<float>::max) ()); little_float32_t little_float32((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(little_float32.data(), VERIFY(std::memcmp(little_float32.data(),
reinterpret_cast<const char*>(&little_float32_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&little_float32_expected), sizeof(float)) == 0);
double big_float64_expected = (std::numeric_limits<double>::max) (); double big_float64_expected = (std::numeric_limits<double>::max) ();
boost::endian::native_to_big_in_place(big_float64_expected); boost::endian::native_to_big_inplace(big_float64_expected);
big_float64_t big_float64((std::numeric_limits<double>::max) ()); big_float64_t big_float64((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(big_float64.data(), VERIFY(std::memcmp(big_float64.data(),
reinterpret_cast<const char*>(&big_float64_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&big_float64_expected), sizeof(double)) == 0);
double little_float64_expected = (std::numeric_limits<double>::max) (); double little_float64_expected = (std::numeric_limits<double>::max) ();
boost::endian::native_to_little_in_place(little_float64_expected); boost::endian::native_to_little_inplace(little_float64_expected);
little_float64_t little_float64((std::numeric_limits<double>::max) ()); little_float64_t little_float64((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(little_float64.data(), VERIFY(std::memcmp(little_float64.data(),
reinterpret_cast<const char*>(&little_float64_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&little_float64_expected), sizeof(double)) == 0);
@@ -639,25 +639,25 @@ namespace
// unaligned floating point types // unaligned floating point types
float big_float32un_expected = (std::numeric_limits<float>::max) (); float big_float32un_expected = (std::numeric_limits<float>::max) ();
boost::endian::native_to_big_in_place(big_float32un_expected); boost::endian::native_to_big_inplace(big_float32un_expected);
big_float32_ut big_float32un((std::numeric_limits<float>::max) ()); big_float32_ut big_float32un((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(big_float32un.data(), VERIFY(std::memcmp(big_float32un.data(),
reinterpret_cast<const char*>(&big_float32un_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&big_float32un_expected), sizeof(float)) == 0);
float little_float32un_expected = (std::numeric_limits<float>::max) (); float little_float32un_expected = (std::numeric_limits<float>::max) ();
boost::endian::native_to_little_in_place(little_float32un_expected); boost::endian::native_to_little_inplace(little_float32un_expected);
little_float32_ut little_float32un((std::numeric_limits<float>::max) ()); little_float32_ut little_float32un((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(little_float32un.data(), VERIFY(std::memcmp(little_float32un.data(),
reinterpret_cast<const char*>(&little_float32un_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&little_float32un_expected), sizeof(float)) == 0);
double big_float64un_expected = (std::numeric_limits<double>::max) (); double big_float64un_expected = (std::numeric_limits<double>::max) ();
boost::endian::native_to_big_in_place(big_float64un_expected); boost::endian::native_to_big_inplace(big_float64un_expected);
big_float64_ut big_float64un((std::numeric_limits<double>::max) ()); big_float64_ut big_float64un((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(big_float64un.data(), VERIFY(std::memcmp(big_float64un.data(),
reinterpret_cast<const char*>(&big_float64un_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&big_float64un_expected), sizeof(double)) == 0);
double little_float64un_expected = (std::numeric_limits<double>::max) (); double little_float64un_expected = (std::numeric_limits<double>::max) ();
boost::endian::native_to_little_in_place(little_float64un_expected); boost::endian::native_to_little_inplace(little_float64un_expected);
little_float64_ut little_float64un((std::numeric_limits<double>::max) ()); little_float64_ut little_float64un((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(little_float64un.data(), VERIFY(std::memcmp(little_float64un.data(),
reinterpret_cast<const char*>(&little_float64un_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&little_float64un_expected), sizeof(double)) == 0);

View File

@@ -101,14 +101,14 @@ namespace
// cout << "***************Endian conversion approach...\n"; // cout << "***************Endian conversion approach...\n";
T x(0); T x(0);
boost::timer::cpu_timer t; boost::timer::cpu_timer t;
native_to_big_in_place(x); native_to_big_inplace(x);
for (uint64_t i = 0; i < n; ++i) for (uint64_t i = 0; i < n; ++i)
{ {
x += static_cast<T>(i); x += static_cast<T>(i);
} }
big_to_native_in_place(x); big_to_native_inplace(x);
t.stop(); t.stop();
native_to_big_in_place(x); native_to_big_inplace(x);
if (x != total) if (x != total)
throw std::logic_error("integer approach total != conversion approach total"); throw std::logic_error("integer approach total != conversion approach total");
cout << "<td align=\"right\">" << t.format(places, "%t") << " s</td>"; cout << "<td align=\"right\">" << t.format(places, "%t") << " s</td>";

View File

@@ -101,7 +101,7 @@ namespace
cout << "<tr><td>16-bit aligned big endian</td>"; cout << "<tr><td>16-bit aligned big endian</td>";
time<int16_t, big_int16_ut>(user::return_x_big_int16); time<int16_t, big_int16_ut>(user::return_x_big_int16);
time<int16_t, big_int16_ut>(user::return_x_value_big_int16); time<int16_t, big_int16_ut>(user::return_x_value_big_int16);
time<int16_t, big_int16_ut>(user::return_x_in_place_big_int16); time<int16_t, big_int16_ut>(user::return_x_inplace_big_int16);
time<int16_t, big_int16_ut>(user::return_x_big_int16); time<int16_t, big_int16_ut>(user::return_x_big_int16);
cout << "</tr>\n"; cout << "</tr>\n";
} }
@@ -111,7 +111,7 @@ namespace
cout << "<tr><td>16-bit aligned little endian</td>"; cout << "<tr><td>16-bit aligned little endian</td>";
time<int16_t, little_int16_ut>(user::return_x_little_int16); time<int16_t, little_int16_ut>(user::return_x_little_int16);
time<int16_t, little_int16_ut>(user::return_x_value_little_int16); time<int16_t, little_int16_ut>(user::return_x_value_little_int16);
time<int16_t, little_int16_ut>(user::return_x_in_place_little_int16); time<int16_t, little_int16_ut>(user::return_x_inplace_little_int16);
time<int16_t, little_int16_ut>(user::return_x_little_int16); time<int16_t, little_int16_ut>(user::return_x_little_int16);
cout << "</tr>\n"; cout << "</tr>\n";
} }
@@ -121,7 +121,7 @@ namespace
cout << "<tr><td>32-bit aligned big endian</td>"; cout << "<tr><td>32-bit aligned big endian</td>";
time<int32_t, big_int32_ut>(user::return_x_big_int32); time<int32_t, big_int32_ut>(user::return_x_big_int32);
time<int32_t, big_int32_ut>(user::return_x_value_big_int32); time<int32_t, big_int32_ut>(user::return_x_value_big_int32);
time<int32_t, big_int32_ut>(user::return_x_in_place_big_int32); time<int32_t, big_int32_ut>(user::return_x_inplace_big_int32);
time<int32_t, big_int32_ut>(user::return_x_big_int32); time<int32_t, big_int32_ut>(user::return_x_big_int32);
cout << "</tr>\n"; cout << "</tr>\n";
} }
@@ -131,7 +131,7 @@ namespace
cout << "<tr><td>32-bit aligned little endian</td>"; cout << "<tr><td>32-bit aligned little endian</td>";
time<int32_t, little_int32_ut>(user::return_x_little_int32); time<int32_t, little_int32_ut>(user::return_x_little_int32);
time<int32_t, little_int32_ut>(user::return_x_value_little_int32); time<int32_t, little_int32_ut>(user::return_x_value_little_int32);
time<int32_t, little_int32_ut>(user::return_x_in_place_little_int32); time<int32_t, little_int32_ut>(user::return_x_inplace_little_int32);
time<int32_t, little_int32_ut>(user::return_x_little_int32); time<int32_t, little_int32_ut>(user::return_x_little_int32);
cout << "</tr>\n"; cout << "</tr>\n";
} }
@@ -141,7 +141,7 @@ namespace
cout << "<tr><td>64-bit aligned big endian</td>"; cout << "<tr><td>64-bit aligned big endian</td>";
time<int64_t, big_int64_ut>(user::return_x_big_int64); time<int64_t, big_int64_ut>(user::return_x_big_int64);
time<int64_t, big_int64_ut>(user::return_x_value_big_int64); time<int64_t, big_int64_ut>(user::return_x_value_big_int64);
time<int64_t, big_int64_ut>(user::return_x_in_place_big_int64); time<int64_t, big_int64_ut>(user::return_x_inplace_big_int64);
time<int64_t, big_int64_ut>(user::return_x_big_int64); time<int64_t, big_int64_ut>(user::return_x_big_int64);
cout << "</tr>\n"; cout << "</tr>\n";
} }
@@ -151,7 +151,7 @@ namespace
cout << "<tr><td>64-bit aligned little endian</td>"; cout << "<tr><td>64-bit aligned little endian</td>";
time<int64_t, little_int64_ut>(user::return_x_little_int64); time<int64_t, little_int64_ut>(user::return_x_little_int64);
time<int64_t, little_int64_ut>(user::return_x_value_little_int64); time<int64_t, little_int64_ut>(user::return_x_value_little_int64);
time<int64_t, little_int64_ut>(user::return_x_in_place_little_int64); time<int64_t, little_int64_ut>(user::return_x_inplace_little_int64);
time<int64_t, little_int64_ut>(user::return_x_little_int64); time<int64_t, little_int64_ut>(user::return_x_little_int64);
cout << "</tr>\n"; cout << "</tr>\n";
} }

View File

@@ -30,13 +30,13 @@ namespace user
{ {
return conditional_reverse<order::native, order::little>(x); return conditional_reverse<order::native, order::little>(x);
} }
int16_t return_x_in_place_big_int16(int16_t x, big_int16_ut) BOOST_NOEXCEPT int16_t return_x_inplace_big_int16(int16_t x, big_int16_ut) BOOST_NOEXCEPT
{ {
conditional_reverse_in_place<order::native, order::big>(x); return x; conditional_reverse_inplace<order::native, order::big>(x); return x;
} }
int16_t return_x_in_place_little_int16(int16_t x, little_int16_ut) BOOST_NOEXCEPT int16_t return_x_inplace_little_int16(int16_t x, little_int16_ut) BOOST_NOEXCEPT
{ {
conditional_reverse_in_place<order::native, order::little>(x); return x; conditional_reverse_inplace<order::native, order::little>(x); return x;
} }
int16_t return_y_big_int16(int16_t x, big_int16_ut y) BOOST_NOEXCEPT { return y; } int16_t return_y_big_int16(int16_t x, big_int16_ut y) BOOST_NOEXCEPT { return y; }
int16_t return_y_little_int16(int16_t x, little_int16_ut y) BOOST_NOEXCEPT { return y; } int16_t return_y_little_int16(int16_t x, little_int16_ut y) BOOST_NOEXCEPT { return y; }
@@ -51,13 +51,13 @@ namespace user
{ {
return conditional_reverse<order::native, order::little>(x); return conditional_reverse<order::native, order::little>(x);
} }
int32_t return_x_in_place_big_int32(int32_t x, big_int32_ut) BOOST_NOEXCEPT int32_t return_x_inplace_big_int32(int32_t x, big_int32_ut) BOOST_NOEXCEPT
{ {
conditional_reverse_in_place<order::native, order::big>(x); return x; conditional_reverse_inplace<order::native, order::big>(x); return x;
} }
int32_t return_x_in_place_little_int32(int32_t x, little_int32_ut) BOOST_NOEXCEPT int32_t return_x_inplace_little_int32(int32_t x, little_int32_ut) BOOST_NOEXCEPT
{ {
conditional_reverse_in_place<order::native, order::little>(x); return x; conditional_reverse_inplace<order::native, order::little>(x); return x;
} }
int32_t return_y_big_int32(int32_t x, big_int32_ut y) BOOST_NOEXCEPT { return y; } int32_t return_y_big_int32(int32_t x, big_int32_ut y) BOOST_NOEXCEPT { return y; }
int32_t return_y_little_int32(int32_t x, little_int32_ut y) BOOST_NOEXCEPT { return y; } int32_t return_y_little_int32(int32_t x, little_int32_ut y) BOOST_NOEXCEPT { return y; }
@@ -72,13 +72,13 @@ namespace user
{ {
return conditional_reverse<order::native, order::little>(x); return conditional_reverse<order::native, order::little>(x);
} }
int64_t return_x_in_place_big_int64(int64_t x, big_int64_ut) BOOST_NOEXCEPT int64_t return_x_inplace_big_int64(int64_t x, big_int64_ut) BOOST_NOEXCEPT
{ {
conditional_reverse_in_place<order::native, order::big>(x); return x; conditional_reverse_inplace<order::native, order::big>(x); return x;
} }
int64_t return_x_in_place_little_int64(int64_t x, little_int64_ut) BOOST_NOEXCEPT int64_t return_x_inplace_little_int64(int64_t x, little_int64_ut) BOOST_NOEXCEPT
{ {
conditional_reverse_in_place<order::native, order::little>(x); return x; conditional_reverse_inplace<order::native, order::little>(x); return x;
} }
int64_t return_y_big_int64(int64_t x, big_int64_ut y) BOOST_NOEXCEPT { return y; } int64_t return_y_big_int64(int64_t x, big_int64_ut y) BOOST_NOEXCEPT { return y; }
int64_t return_y_little_int64(int64_t x, little_int64_ut y) BOOST_NOEXCEPT { return y; } int64_t return_y_little_int64(int64_t x, little_int64_ut y) BOOST_NOEXCEPT { return y; }