Change memcpy to memmove in example as ranges may overlap.

Update/regenerate docs.

[SVN r61550]
This commit is contained in:
John Maddock
2010-04-25 08:29:57 +00:00
parent cf879100c6
commit 9dd5a79afa
28 changed files with 109 additions and 40 deletions

View File

@ -36,7 +36,7 @@ determine whether to use `memcpy` to optimise the copy operation
template<typename T>
T* copy_imp(const T* first, const T* last, T* out, const boost::__true_type&)
{
memcpy(out, first, (last-first)*sizeof(T));
memmove(out, first, (last-first)*sizeof(T));
return out+(last-first);
}

View File

@ -56,7 +56,7 @@
method available to them.
</p>
<a name="boost_typetraits.background.type_traits"></a><h5>
<a name="id769755"></a>
<a name="id769782"></a>
<a class="link" href="background.html#boost_typetraits.background.type_traits">Type Traits</a>
</h5>
<p>
@ -84,7 +84,7 @@
given.
</p>
<a name="boost_typetraits.background.implementation"></a><h5>
<a name="id769818"></a>
<a name="id769846"></a>
<a class="link" href="background.html#boost_typetraits.background.implementation">Implementation</a>
</h5>
<p>
@ -174,7 +174,7 @@
in the default template.
</p>
<a name="boost_typetraits.background.optimized_copy"></a><h5>
<a name="id778597"></a>
<a name="id778570"></a>
<a class="link" href="background.html#boost_typetraits.background.optimized_copy">Optimized copy</a>
</h5>
<p>
@ -247,7 +247,7 @@
otherwise it will call the "slow but safe version".
</p>
<a name="boost_typetraits.background.was_it_worth_it_"></a><h5>
<a name="id778944"></a>
<a name="id778917"></a>
<a class="link" href="background.html#boost_typetraits.background.was_it_worth_it_">Was it worth it?</a>
</h5>
<p>
@ -280,7 +280,7 @@
</li>
</ul></div>
<div class="table">
<a name="id778981"></a><p class="title"><b>Table&#160;1.1.&#160;Time taken to copy 1000 elements using `copy&lt;const
<a name="id778954"></a><p class="title"><b>Table&#160;1.1.&#160;Time taken to copy 1000 elements using `copy&lt;const
T*, T*&gt;` (times in micro-seconds)</b></p>
<div class="table-contents"><table class="table" summary="Time taken to copy 1000 elements using `copy&lt;const
T*, T*&gt;` (times in micro-seconds)">
@ -379,7 +379,7 @@
</table></div>
</div>
<br class="table-break"><a name="boost_typetraits.background.pair_of_references"></a><h5>
<a name="id779119"></a>
<a name="id779092"></a>
<a class="link" href="background.html#boost_typetraits.background.pair_of_references">Pair of References</a>
</h5>
<p>
@ -416,7 +416,7 @@
to hold non-reference types, references, and constant references:
</p>
<div class="table">
<a name="id779380"></a><p class="title"><b>Table&#160;1.2.&#160;Required Constructor Argument Types</b></p>
<a name="id779354"></a><p class="title"><b>Table&#160;1.2.&#160;Required Constructor Argument Types</b></p>
<div class="table-contents"><table class="table" summary="Required Constructor Argument Types">
<colgroup>
<col>
@ -481,7 +481,7 @@
adds a reference to its type, unless it is already a reference.
</p>
<div class="table">
<a name="id779484"></a><p class="title"><b>Table&#160;1.3.&#160;Using add_reference to synthesize the correct constructor
<a name="id779457"></a><p class="title"><b>Table&#160;1.3.&#160;Using add_reference to synthesize the correct constructor
type</b></p>
<div class="table-contents"><table class="table" summary="Using add_reference to synthesize the correct constructor
type">
@ -598,7 +598,7 @@
easier to maintain and easier to understand.
</p>
<a name="boost_typetraits.background.conclusion"></a><h5>
<a name="id779942"></a>
<a name="id779915"></a>
<a class="link" href="background.html#boost_typetraits.background.conclusion">Conclusion</a>
</h5>
<p>
@ -611,7 +611,7 @@
can be optimal as well as generic.
</p>
<a name="boost_typetraits.background.acknowledgements"></a><h5>
<a name="id779959"></a>
<a name="id779932"></a>
<a class="link" href="background.html#boost_typetraits.background.acknowledgements">Acknowledgements</a>
</h5>
<p>
@ -619,7 +619,7 @@
comments when preparing this article.
</p>
<a name="background.references"></a><a name="boost_typetraits.background.references"></a><h5>
<a name="id779979"></a>
<a name="id779953"></a>
<a class="link" href="background.html#boost_typetraits.background.references">References</a>
</h5>
<div class="orderedlist"><ol type="1">

View File

@ -91,7 +91,7 @@
<span class="keyword">struct</span> <a class="link" href="../reference/remove_volatile.html" title="remove_volatile">remove_volatile</a><span class="special">;</span>
</pre>
<a name="boost_typetraits.category.transform.broken_compiler_workarounds_"></a><h5>
<a name="id783771"></a>
<a name="id783745"></a>
<a class="link" href="transform.html#boost_typetraits.category.transform.broken_compiler_workarounds_">Broken
Compiler Workarounds:</a>
</h5>

View File

@ -56,7 +56,7 @@
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">T</span><span class="special">*</span> <span class="identifier">copy_imp</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">first</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">out</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><a class="link" href="../reference/integral_constant.html" title="integral_constant">true_type</a><span class="special">&amp;)</span>
<span class="special">{</span>
<span class="identifier">memcpy</span><span class="special">(</span><span class="identifier">out</span><span class="special">,</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">last</span><span class="special">-</span><span class="identifier">first</span><span class="special">)*</span><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">));</span>
<span class="identifier">memmove</span><span class="special">(</span><span class="identifier">out</span><span class="special">,</span> <span class="identifier">first</span><span class="special">,</span> <span class="special">(</span><span class="identifier">last</span><span class="special">-</span><span class="identifier">first</span><span class="special">)*</span><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">));</span>
<span class="keyword">return</span> <span class="identifier">out</span><span class="special">+(</span><span class="identifier">last</span><span class="special">-</span><span class="identifier">first</span><span class="special">);</span>
<span class="special">}</span>

View File

@ -27,7 +27,7 @@
<a name="boost_typetraits.history"></a><a class="link" href="history.html" title="History"> History</a>
</h2></div></div></div>
<a name="boost_typetraits.history.boost_1_42_0"></a><h5>
<a name="id832026"></a>
<a name="id832817"></a>
<a class="link" href="history.html#boost_typetraits.history.boost_1_42_0">Boost 1.42.0</a>
</h5>
<div class="itemizedlist"><ul type="disc"><li>

View File

@ -71,7 +71,7 @@
of the following macros:
</p>
<div class="table">
<a name="id785322"></a><p class="title"><b>Table&#160;1.4.&#160;Macros for Compiler Intrinsics</b></p>
<a name="id785295"></a><p class="title"><b>Table&#160;1.4.&#160;Macros for Compiler Intrinsics</b></p>
<div class="table-contents"><table class="table" summary="Macros for Compiler Intrinsics">
<colgroup>
<col>

View File

@ -53,7 +53,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id790399"></a><p class="title"><b>Table&#160;1.5.&#160;Examples</b></p>
<a name="id790236"></a><p class="title"><b>Table&#160;1.5.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -54,7 +54,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id790870"></a><p class="title"><b>Table&#160;1.6.&#160;Examples</b></p>
<a name="id790707"></a><p class="title"><b>Table&#160;1.6.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -56,7 +56,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id791394"></a><p class="title"><b>Table&#160;1.7.&#160;Examples</b></p>
<a name="id792869"></a><p class="title"><b>Table&#160;1.7.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -53,7 +53,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id793571"></a><p class="title"><b>Table&#160;1.8.&#160;Examples</b></p>
<a name="id793340"></a><p class="title"><b>Table&#160;1.8.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -53,7 +53,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id794036"></a><p class="title"><b>Table&#160;1.9.&#160;Examples</b></p>
<a name="id793804"></a><p class="title"><b>Table&#160;1.9.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -48,7 +48,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id795288"></a><p class="title"><b>Table&#160;1.10.&#160;Examples</b></p>
<a name="id795331"></a><p class="title"><b>Table&#160;1.10.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -49,7 +49,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id797142"></a><p class="title"><b>Table&#160;1.11.&#160;Examples</b></p>
<a name="id796911"></a><p class="title"><b>Table&#160;1.11.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -59,7 +59,7 @@
</p></td></tr>
</table></div>
<div class="table">
<a name="id797504"></a><p class="title"><b>Table&#160;1.12.&#160;Function Traits Members</b></p>
<a name="id797272"></a><p class="title"><b>Table&#160;1.12.&#160;Function Traits Members</b></p>
<div class="table-contents"><table class="table" summary="Function Traits Members">
<colgroup>
<col>
@ -122,7 +122,7 @@
</table></div>
</div>
<br class="table-break"><div class="table">
<a name="id797716"></a><p class="title"><b>Table&#160;1.13.&#160;Examples</b></p>
<a name="id797485"></a><p class="title"><b>Table&#160;1.13.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -49,7 +49,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id805969"></a><p class="title"><b>Table&#160;1.14.&#160;Examples</b></p>
<a name="id805670"></a><p class="title"><b>Table&#160;1.14.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -54,7 +54,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id824336"></a><p class="title"><b>Table&#160;1.15.&#160;Examples</b></p>
<a name="id825124"></a><p class="title"><b>Table&#160;1.15.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -54,7 +54,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id825909"></a><p class="title"><b>Table&#160;1.16.&#160;Examples</b></p>
<a name="id826697"></a><p class="title"><b>Table&#160;1.16.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -51,7 +51,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id826426"></a><p class="title"><b>Table&#160;1.17.&#160;Examples</b></p>
<a name="id827214"></a><p class="title"><b>Table&#160;1.17.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -54,7 +54,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id827544"></a><p class="title"><b>Table&#160;1.18.&#160;Examples</b></p>
<a name="id828331"></a><p class="title"><b>Table&#160;1.18.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -53,7 +53,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id828700"></a><p class="title"><b>Table&#160;1.19.&#160;Examples</b></p>
<a name="id829487"></a><p class="title"><b>Table&#160;1.19.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -53,7 +53,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id829223"></a><p class="title"><b>Table&#160;1.20.&#160;Examples</b></p>
<a name="id830010"></a><p class="title"><b>Table&#160;1.20.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -54,7 +54,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id829745"></a><p class="title"><b>Table&#160;1.21.&#160;Examples</b></p>
<a name="id830532"></a><p class="title"><b>Table&#160;1.21.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -55,7 +55,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id830292"></a><p class="title"><b>Table&#160;1.22.&#160;Examples</b></p>
<a name="id831080"></a><p class="title"><b>Table&#160;1.22.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -53,7 +53,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id831071"></a><p class="title"><b>Table&#160;1.23.&#160;Examples</b></p>
<a name="id831862"></a><p class="title"><b>Table&#160;1.23.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -53,7 +53,7 @@
or <code class="computeroutput"> <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<div class="table">
<a name="id831520"></a><p class="title"><b>Table&#160;1.24.&#160;Examples</b></p>
<a name="id832311"></a><p class="title"><b>Table&#160;1.24.&#160;Examples</b></p>
<div class="table-contents"><table class="table" summary="Examples">
<colgroup>
<col>

View File

@ -30,7 +30,7 @@
Marcus, Itay Maman, John Maddock, Alexander Nasonov, Thorsten Ottosen, Robert
Ramey and Jeremy Siek</p></div>
<div><div class="legalnotice">
<a name="id769606"></a><p>
<a name="id769633"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>

View File

@ -52,7 +52,7 @@ I2 copy_imp(I1 first, I1 last, I2 out, const boost::integral_constant<bool, b>&)
template<typename T>
T* copy_imp(const T* first, const T* last, T* out, const boost::true_type&)
{
memcpy(out, first, (last-first)*sizeof(T));
memmove(out, first, (last-first)*sizeof(T));
return out+(last-first);
}
@ -71,7 +71,18 @@ inline I2 copy(I1 first, I1 last, I2 out)
return detail::copy_imp(first, last, out, boost::has_trivial_assign<value_type>());
}
}; // namespace opt
} // namespace opt
namespace non_opt
{
template<typename I1, typename I2>
inline I2 copy(I1 first, I1 last, I2 out)
{
return opt::detail::copy_imp(first, last, out, boost::false_type());
}
}
//
// define some global data:
@ -114,6 +125,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::copy<const int*, int*>: " << result << endl;
// cache load:
non_opt::copy(ci_array, ci_array + array_size, i_array);
// time non-optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::copy(ci_array, ci_array + array_size, i_array);
}
result = t.elapsed();
cout << "non_opt::copy<const int*, int*>: " << result << endl;
// cache load:
std::copy(ci_array, ci_array + array_size, i_array);
@ -138,6 +161,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::copy<const char*, char*>: " << result << endl;
// cache load:
non_opt::copy(cc_array, cc_array + array_size, c_array);
// time optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::copy(cc_array, cc_array + array_size, c_array);
}
result = t.elapsed();
cout << "non_opt::copy<const char*, char*>: " << result << endl;
// cache load:
std::copy(cc_array, cc_array + array_size, c_array);

View File

@ -69,7 +69,17 @@ inline void fill(I first, I last, const T& val)
detail::do_fill(first, last, val, truth_type());
}
}; // namespace opt
} // namespace opt
namespace non_opt{
template <class I, class T>
inline void fill(I first, I last, const T& val)
{
opt::detail::do_fill(first, last, val, boost::false_type());
}
}
//
// define some global data:
@ -118,6 +128,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::fill<char*, char>: " << result << endl;
// cache load:
non_opt::fill(c_array, c_array + array_size, (char)3);
// time optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::fill(c_array, c_array + array_size, (char)3);
}
result = t.elapsed();
cout << "non_opt::fill<char*, char>: " << result << endl;
// cache load:
std::fill(c_array, c_array + array_size, (char)3);
@ -144,6 +166,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::fill<int*, int>: " << result << endl;
// cache load:
non_opt::fill(i_array, i_array + array_size, 3);
// timer optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::fill(i_array, i_array + array_size, 3);
}
result = t.elapsed();
cout << "non_opt::fill<int*, int>: " << result << endl;
// cache load:
std::fill(i_array, i_array + array_size, 3);