Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <title>thrust: Copying</title> <link href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Ftabs.css" rel="stylesheet" type="text/css"/> <link href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdoxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">thrust </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.6.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Findex.html"><span>Main Page</span></a></li> <li><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fmodules.html"><span>Modules</span></a></li> <li><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fnamespaces.html"><span>Namespaces</span></a></li> <li><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fannotated.html"><span>Classes</span></a></li> <li><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Ffiles.html"><span>Files</span></a></li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fthrust.docs%23groups">Modules</a> | <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fthrust.docs%23func-members">Functions</a> </div> <div class="headertitle"> <div class="title">Copying</div> </div> <div class="ingroups"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__algorithms.html">Algorithms</a></div></div><!--header--> <div class="contents"> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="groups"></a> Modules</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__gathering.html">Gathering</a></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__scattering.html">Scattering</a></td></tr> <tr><td colspan="2"><h2><a name="func-members"></a> Functions</h2></td></tr> <tr><td class="memTemplParams" colspan="2">template<typename InputIterator , typename OutputIterator > </td></tr> <tr><td class="memTemplItemLeft" align="right" valign="top">OutputIterator </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24ccfaaa706a9163ec5117758fdb71b9">thrust::copy</a> (InputIterator first, InputIterator last, OutputIterator result)</td></tr> <tr><td class="memTemplParams" colspan="2">template<typename InputIterator , typename Size , typename OutputIterator > </td></tr> <tr><td class="memTemplItemLeft" align="right" valign="top">OutputIterator </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23gab3d33f1aa1d078b5f6b579f07313d058">thrust::copy_n</a> (InputIterator first, Size n, OutputIterator result)</td></tr> <tr><td class="memTemplParams" colspan="2">template<typename ForwardIterator1 , typename ForwardIterator2 > </td></tr> <tr><td class="memTemplItemLeft" align="right" valign="top">ForwardIterator2 </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24337437822d9f7ca85f0c48b9248f6e">thrust::swap_ranges</a> (ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)</td></tr> <tr><td class="memTemplParams" colspan="2">template<typename InputIterator , typename ForwardIterator > </td></tr> <tr><td class="memTemplItemLeft" align="right" valign="top">ForwardIterator </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga50ecdff4f2b8c7606f837e1cfeb70f24">thrust::uninitialized_copy</a> (InputIterator first, InputIterator last, ForwardIterator result)</td></tr> <tr><td class="memTemplParams" colspan="2">template<typename InputIterator , typename Size , typename ForwardIterator > </td></tr> <tr><td class="memTemplItemLeft" align="right" valign="top">ForwardIterator </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23gabe36cff9b0dcf6a52869a725379eb726">thrust::uninitialized_copy_n</a> (InputIterator first, Size n, ForwardIterator result)</td></tr> </table> <hr/><h2>Function Documentation</h2> <a class="anchor" id="ga24ccfaaa706a9163ec5117758fdb71b9"></a><!-- doxytag: member="thrust::copy" ref="ga24ccfaaa706a9163ec5117758fdb71b9" args="(InputIterator first, InputIterator last, OutputIterator result)" --> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename InputIterator , typename OutputIterator > </div> <table class="memname"> <tr> <td class="memname">OutputIterator <a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24ccfaaa706a9163ec5117758fdb71b9">thrust::copy</a> </td> <td>(</td> <td class="paramtype">InputIterator </td> <td class="paramname"><em>first</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">InputIterator </td> <td class="paramname"><em>last</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">OutputIterator </td> <td class="paramname"><em>result</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p><code>copy</code> copies elements from the range [<code>first</code>, <code>last</code>) to the range [<code>result</code>, <code>result</code> + (<code>last</code> - <code>first</code>)). That is, it performs the assignments *<code>result</code> = *<code>first</code>, *(<code>result</code> + <code>1</code>) = *(<code>first</code> + <code>1</code>), and so on. Generally, for every integer <code>n</code> from <code>0</code> to <code>last</code> - <code>first</code>, <code>copy</code> performs the assignment *(<code>result</code> + <code>n</code>) = *(<code>first</code> + <code>n</code>). Unlike <code>std::copy</code>, <code>copy</code> offers no guarantee on order of operation. As a result, calling <code>copy</code> with overlapping source and destination ranges has undefined behavior.</p> <p>The return value is <code>result</code> + (<code>last</code> - <code>first</code>).</p> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">first</td><td>The beginning of the sequence to copy. </td></tr> <tr><td class="paramname">last</td><td>The end of the sequence to copy. </td></tr> <tr><td class="paramname">result</td><td>The destination sequence. </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>The end of the destination sequence. </dd></dl> <dl class="see"><dt><b>See also:</b></dt><dd><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/copy.html">http://www.sgi.com/tech/stl/copy.html</a></dd></dl" rel="nofollow">http://www.sgi.com/tech/stl/copy.html">http://www.sgi.com/tech/stl/copy.html</a></dd></dl> <dl class=""><dt><b>Template Parameters:</b></dt><dd> <table class=""> <tr><td class="paramname">InputIterator</td><td>must be a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/InputIterator.html">Input" rel="nofollow">http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and <code>InputIterator's</code> <code>value_type</code> must be convertible to <code>OutputIterator's</code> <code>value_type</code>. </td></tr> <tr><td class="paramname">OutputIterator</td><td>must be a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/OutputIterator.html">Output" rel="nofollow">http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.</td></tr> </table> </dd> </dl> <p>The following code snippet demonstrates how to use <code>copy</code> to copy from one range to another.</p> <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fcopy_8h.html" title="Copies elements from one range to another.">thrust/copy.h</a>></span> <span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdevice__vector_8h.html" title="A dynamically-sizable array of elements which reside in the "device" memory space.">thrust/device_vector.h</a>></span> ... <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__vector.html">thrust::device_vector<int></a> vec0(100); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__vector.html">thrust::device_vector<int></a> vec1(100); ... <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24ccfaaa706a9163ec5117758fdb71b9">thrust::copy</a>(vec0.begin(), vec0.end(), vec1.begin()); <span class="comment">// vec1 is now a copy of vec0</span> </pre></div> </div> </div> <a class="anchor" id="gab3d33f1aa1d078b5f6b579f07313d058"></a><!-- doxytag: member="thrust::copy_n" ref="gab3d33f1aa1d078b5f6b579f07313d058" args="(InputIterator first, Size n, OutputIterator result)" --> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename InputIterator , typename Size , typename OutputIterator > </div> <table class="memname"> <tr> <td class="memname">OutputIterator <a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23gab3d33f1aa1d078b5f6b579f07313d058">thrust::copy_n</a> </td> <td>(</td> <td class="paramtype">InputIterator </td> <td class="paramname"><em>first</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">Size </td> <td class="paramname"><em>n</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">OutputIterator </td> <td class="paramname"><em>result</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p><code>copy_n</code> copies elements from the range <code>[first, first + n)</code> to the range <code>[result, result + n)</code>. That is, it performs the assignments <code>*result = *first, *(result + 1) = *(first + 1)</code>, and so on. Generally, for every integer <code>i</code> from <code>0</code> to <code>n</code>, <code>copy</code> performs the assignment *(<code>result</code> + <code>i</code>) = *(<code>first</code> + <code>i</code>). Unlike <code>std::copy_n</code>, <code>copy_n</code> offers no guarantee on order of operation. As a result, calling <code>copy_n</code> with overlapping source and destination ranges has undefined behavior.</p> <p>The return value is <code>result</code> + <code>n</code>.</p> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">first</td><td>The beginning of the range to copy. </td></tr> <tr><td class="paramname">n</td><td>The number of elements to copy. </td></tr> <tr><td class="paramname">result</td><td>The beginning destination range. </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>The end of the destination range.</dd></dl> <dl class=""><dt><b>Template Parameters:</b></dt><dd> <table class=""> <tr><td class="paramname">InputIterator</td><td>must be a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/InputIterator.html">Input" rel="nofollow">http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and <code>InputIterator's</code> <code>value_type</code> must be convertible to <code>OutputIterator's</code> <code>value_type</code>. </td></tr> <tr><td class="paramname">Size</td><td>is an integral type. </td></tr> <tr><td class="paramname">OutputIterator</td><td>must be a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/OutputIterator.html">Output" rel="nofollow">http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.</td></tr> </table> </dd> </dl> <p>The following code snippet demonstrates how to use <code>copy</code> to copy from one range to another.</p> <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fcopy_8h.html" title="Copies elements from one range to another.">thrust/copy.h</a>></span> <span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdevice__vector_8h.html" title="A dynamically-sizable array of elements which reside in the "device" memory space.">thrust/device_vector.h</a>></span> ... <span class="keywordtype">size_t</span> n = 100; <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__vector.html">thrust::device_vector<int></a> vec0(n); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__vector.html">thrust::device_vector<int></a> vec1(n); ... <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23gab3d33f1aa1d078b5f6b579f07313d058">thrust::copy_n</a>(vec0.begin(), n, vec1.begin()); <span class="comment">// vec1 is now a copy of vec0</span> </pre></div><dl class="see"><dt><b>See also:</b></dt><dd><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/copy_n.html">http://www.sgi.com/tech/stl/copy_n.html</a" rel="nofollow">http://www.sgi.com/tech/stl/copy_n.html">http://www.sgi.com/tech/stl/copy_n.html</a> </dd> <dd> <a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24ccfaaa706a9163ec5117758fdb71b9">thrust::copy</a> </dd></dl> </div> </div> <a class="anchor" id="ga24337437822d9f7ca85f0c48b9248f6e"></a><!-- doxytag: member="thrust::swap_ranges" ref="ga24337437822d9f7ca85f0c48b9248f6e" args="(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)" --> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename ForwardIterator1 , typename ForwardIterator2 > </div> <table class="memname"> <tr> <td class="memname">ForwardIterator2 <a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24337437822d9f7ca85f0c48b9248f6e">thrust::swap_ranges</a> </td> <td>(</td> <td class="paramtype">ForwardIterator1 </td> <td class="paramname"><em>first1</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">ForwardIterator1 </td> <td class="paramname"><em>last1</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">ForwardIterator2 </td> <td class="paramname"><em>first2</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p><code>swap_ranges</code> swaps each of the elements in the range <code>[first1, last1)</code> with the corresponding element in the range <code>[first2, first2 + (last1 - first1))</code>. That is, for each integer <code>n</code> such that <code>0 <= n < (last1 - first1)</code>, it swaps <code>*(first1 + n)</code> and <code>*(first2 + n)</code>. The return value is <code>first2 + (last1 - first1)</code>.</p> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">first1</td><td>The beginning of the first sequence to swap. </td></tr> <tr><td class="paramname">last1</td><td>One position past the last element of the first sequence to swap. </td></tr> <tr><td class="paramname">first2</td><td>The beginning of the second sequence to swap. </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>An iterator pointing to one position past the last element of the second sequence to swap.</dd></dl> <dl class=""><dt><b>Template Parameters:</b></dt><dd> <table class=""> <tr><td class="paramname">ForwardIterator1</td><td>is a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/ForwardIterator.html">Forward" rel="nofollow">http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>, and <code>ForwardIterator1's</code> <code>value_type</code> must be convertible to <code>ForwardIterator2's</code> <code>value_type</code>. </td></tr> <tr><td class="paramname">ForwardIterator2</td><td>is a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/ForwardIterator.html">Forward" rel="nofollow">http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>, and <code>ForwardIterator2's</code> <code>value_type</code> must be convertible to <code>ForwardIterator1's</code> <code>value_type</code>.</td></tr> </table> </dd> </dl> <p>The following code snippet demonstrates how to use <code>swap_ranges</code> to swap the contents of two <code>thrust::device_vectors</code>.</p> <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fswap_8h.html" title="Functions for swapping the value of elements.">thrust/swap.h</a>></span> <span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdevice__vector_8h.html" title="A dynamically-sizable array of elements which reside in the "device" memory space.">thrust/device_vector.h</a>></span> ... <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__vector.html">thrust::device_vector<int></a> v1(2), v2(2); v1[0] = 1; v1[1] = 2; v2[0] = 3; v2[1] = 4; <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24337437822d9f7ca85f0c48b9248f6e">thrust::swap_ranges</a>(v1.begin(), v1.end(), v2.begin()); <span class="comment">// v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2</span> </pre></div><dl class="see"><dt><b>See also:</b></dt><dd><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/swap_ranges.html">http://www.sgi.com/tech/stl/swap_ranges.html</a" rel="nofollow">http://www.sgi.com/tech/stl/swap_ranges.html">http://www.sgi.com/tech/stl/swap_ranges.html</a> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__memory__management__classes.html%23gaa677af4b24a5b9067359809a1f5df3e7">swap</a></code> </dd></dl> </div> </div> <a class="anchor" id="ga50ecdff4f2b8c7606f837e1cfeb70f24"></a><!-- doxytag: member="thrust::uninitialized_copy" ref="ga50ecdff4f2b8c7606f837e1cfeb70f24" args="(InputIterator first, InputIterator last, ForwardIterator result)" --> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename InputIterator , typename ForwardIterator > </div> <table class="memname"> <tr> <td class="memname">ForwardIterator <a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga50ecdff4f2b8c7606f837e1cfeb70f24">thrust::uninitialized_copy</a> </td> <td>(</td> <td class="paramtype">InputIterator </td> <td class="paramname"><em>first</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">InputIterator </td> <td class="paramname"><em>last</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">ForwardIterator </td> <td class="paramname"><em>result</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>In <code>thrust</code>, the function <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__allocation__functions.html%23ga6a56463dcea00aaefa0371f80a462f4e">thrust::device_new</a></code> allocates memory for an object and then creates an object at that location by calling a constructor. Occasionally, however, it is useful to separate those two operations. If each iterator in the range <code>[result, result + (last - first))</code> points to uninitialized memory, then <code>uninitialized_copy</code> creates a copy of <code>[first, last)</code> in that range. That is, for each iterator <code>i</code> in the input, <code>uninitialized_copy</code> creates a copy of <code>*i</code> in the location pointed to by the corresponding iterator in the output range by <code>ForwardIterator's</code> <code>value_type's</code> copy constructor with *i as its argument.</p> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">first</td><td>The first element of the input range to copy from. </td></tr> <tr><td class="paramname">last</td><td>The last element of the input range to copy from. </td></tr> <tr><td class="paramname">result</td><td>The first element of the output range to copy to. </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>An iterator pointing to the last element of the output range.</dd></dl> <dl class=""><dt><b>Template Parameters:</b></dt><dd> <table class=""> <tr><td class="paramname">InputIterator</td><td>is a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/InputIterator.html">Input" rel="nofollow">http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>. </td></tr> <tr><td class="paramname">ForwardIterator</td><td>is a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/ForwardIterator.html">Forward" rel="nofollow">http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>, <code>ForwardIterator</code> is mutable, and <code>ForwardIterator's</code> <code>value_type</code> has a constructor that takes a single argument whose type is <code>InputIterator's</code> <code>value_type</code>.</td></tr> </table> </dd> </dl> <p>The following code snippet demonstrates how to use <code>uninitialized_copy</code> to initialize a range of uninitialized memory.</p> <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Funinitialized__copy_8h.html" title="Copy construction into a range of uninitialized elements from a source range.">thrust/uninitialized_copy.h</a>></span> <span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdevice__malloc_8h.html" title="Allocates storage in device memory.">thrust/device_malloc.h</a>></span> <span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdevice__vector_8h.html" title="A dynamically-sizable array of elements which reside in the "device" memory space.">thrust/device_vector.h</a>></span> ... <span class="keyword">struct </span>Int { __host__ __device__ Int(<span class="keywordtype">int</span> x) : val(x) {} <span class="keywordtype">int</span> val; }; ... <span class="keyword">const</span> <span class="keywordtype">int</span> N = 137; Int val(46); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__vector.html">thrust::device_vector<Int></a> input(N, val); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__ptr.html">thrust::device_ptr<Int></a> array = thrust::device_malloc<Int>(N); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga50ecdff4f2b8c7606f837e1cfeb70f24">thrust::uninitialized_copy</a>(input.begin(), input.end(), array); <span class="comment">// Int x = array[i];</span> <span class="comment">// x.val == 46 for all 0 <= i < N</span> </pre></div><dl class="see"><dt><b>See also:</b></dt><dd><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/uninitialized_copy.html">http://www.sgi.com/tech/stl/uninitialized_copy.html</a" rel="nofollow">http://www.sgi.com/tech/stl/uninitialized_copy.html">http://www.sgi.com/tech/stl/uninitialized_copy.html</a> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24ccfaaa706a9163ec5117758fdb71b9">copy</a></code> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__filling.html%23ga5037eb05758b347f7b376f50b78f187e">uninitialized_fill</a></code> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__allocation__functions.html%23ga6a56463dcea00aaefa0371f80a462f4e">device_new</a></code> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__allocation__functions.html%23ga53081c2b134f091a080c976a1cbaf8cd">device_malloc</a></code> </dd></dl> </div> </div> <a class="anchor" id="gabe36cff9b0dcf6a52869a725379eb726"></a><!-- doxytag: member="thrust::uninitialized_copy_n" ref="gabe36cff9b0dcf6a52869a725379eb726" args="(InputIterator first, Size n, ForwardIterator result)" --> <div class="memitem"> <div class="memproto"> <div class="memtemplate"> template<typename InputIterator , typename Size , typename ForwardIterator > </div> <table class="memname"> <tr> <td class="memname">ForwardIterator <a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23gabe36cff9b0dcf6a52869a725379eb726">thrust::uninitialized_copy_n</a> </td> <td>(</td> <td class="paramtype">InputIterator </td> <td class="paramname"><em>first</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">Size </td> <td class="paramname"><em>n</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">ForwardIterator </td> <td class="paramname"><em>result</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>In <code>thrust</code>, the function <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__allocation__functions.html%23ga6a56463dcea00aaefa0371f80a462f4e">thrust::device_new</a></code> allocates memory for an object and then creates an object at that location by calling a constructor. Occasionally, however, it is useful to separate those two operations. If each iterator in the range <code>[result, result + n)</code> points to uninitialized memory, then <code>uninitialized_copy_n</code> creates a copy of <code>[first, first + n)</code> in that range. That is, for each iterator <code>i</code> in the input, <code>uninitialized_copy_n</code> creates a copy of <code>*i</code> in the location pointed to by the corresponding iterator in the output range by <code>InputIterator's</code> <code>value_type's</code> copy constructor with *i as its argument.</p> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">first</td><td>The first element of the input range to copy from. </td></tr> <tr><td class="paramname">n</td><td>The number of elements to copy. </td></tr> <tr><td class="paramname">result</td><td>The first element of the output range to copy to. </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>An iterator pointing to the last element of the output range.</dd></dl> <dl class=""><dt><b>Template Parameters:</b></dt><dd> <table class=""> <tr><td class="paramname">InputIterator</td><td>is a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/InputIterator.html">Input" rel="nofollow">http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>. </td></tr> <tr><td class="paramname">Size</td><td>is an integral type. </td></tr> <tr><td class="paramname">ForwardIterator</td><td>is a model of <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/ForwardIterator.html">Forward" rel="nofollow">http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>, <code>ForwardIterator</code> is mutable, and <code>ForwardIterator's</code> <code>value_type</code> has a constructor that takes a single argument whose type is <code>InputIterator's</code> <code>value_type</code>.</td></tr> </table> </dd> </dl> <p>The following code snippet demonstrates how to use <code>uninitialized_copy</code> to initialize a range of uninitialized memory.</p> <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Funinitialized__copy_8h.html" title="Copy construction into a range of uninitialized elements from a source range.">thrust/uninitialized_copy.h</a>></span> <span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdevice__malloc_8h.html" title="Allocates storage in device memory.">thrust/device_malloc.h</a>></span> <span class="preprocessor"> #include <<a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdevice__vector_8h.html" title="A dynamically-sizable array of elements which reside in the "device" memory space.">thrust/device_vector.h</a>></span> ... <span class="keyword">struct </span>Int { __host__ __device__ Int(<span class="keywordtype">int</span> x) : val(x) {} <span class="keywordtype">int</span> val; }; ... <span class="keyword">const</span> <span class="keywordtype">int</span> N = 137; Int val(46); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__vector.html">thrust::device_vector<Int></a> input(N, val); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fclassthrust_1_1device__ptr.html">thrust::device_ptr<Int></a> array = thrust::device_malloc<Int>(N); <a class="code" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23gabe36cff9b0dcf6a52869a725379eb726">thrust::uninitialized_copy_n</a>(input.begin(), N, array); <span class="comment">// Int x = array[i];</span> <span class="comment">// x.val == 46 for all 0 <= i < N</span> </pre></div><dl class="see"><dt><b>See also:</b></dt><dd><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.sgi.com/tech/stl/uninitialized_copy.html">http://www.sgi.com/tech/stl/uninitialized_copy.html</a" rel="nofollow">http://www.sgi.com/tech/stl/uninitialized_copy.html">http://www.sgi.com/tech/stl/uninitialized_copy.html</a> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga50ecdff4f2b8c7606f837e1cfeb70f24">uninitialized_copy</a></code> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__copying.html%23ga24ccfaaa706a9163ec5117758fdb71b9">copy</a></code> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__filling.html%23ga5037eb05758b347f7b376f50b78f187e">uninitialized_fill</a></code> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__allocation__functions.html%23ga6a56463dcea00aaefa0371f80a462f4e">device_new</a></code> </dd> <dd> <code><a class="el" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fgroup__allocation__functions.html%23ga53081c2b134f091a080c976a1cbaf8cd">device_malloc</a></code> </dd></dl> </div> </div> </div><!-- contents --> <hr class="footer"/><address class="footer"><small> Generated on Wed Mar 7 2012 17:18:41 for thrust by  <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2F%3Ca+href%3D"http://www.doxygen.org/index.html" rel="nofollow">http://www.doxygen.org/index.html"> <img class="footer" src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbfurtaw%2Fdoxygen.png" alt="doxygen"/> </a> 1.7.6.1 </small></address> </body> </html>