Boost C++ Libraries: Ticket #8409: copy_n https://svn.boost.org/trac10/ticket/8409 <p> feature request: Boost.Range doesnt have a copy_n algorithm, I guess because the range already includes a "size". it's still useful if you need to copy N elements but don't know if the range has enough elements. you can't easily check because you don't know whether the range is random access. </p> <pre class="wiki">if(copy_n(range,size,out) != out+size) throw something; </pre><pre class="wiki">template&lt;class Range,class Size,class OutputIterator&gt; OutputIterator copy_n(Range const &amp;r,Size s,OutputIterator const &amp;out,std::random_access_iterator_tag){ if(s &lt;= size(r) return range_copy(r,out); else return out; } template&lt;class Range,class Size,class OutputIterator,class InCat&gt; OutputIterator copy_n(Range const &amp;r,Size s,OutputIterator out,InCat){ typename range_const_iterator&lt;Range&gt;::type it=begin(r); for(std::size_t c=0;c&lt;s &amp;&amp; it != end(r);++c){ *out++=*it++; } return out; } template&lt;class Range,class Size,class OutputIterator&gt; OutputIterator copy_n(Range const &amp;r,Size size,OutputIterator const &amp;out){ return detail::copy_n(r,size,out,typename range_category&lt;Range&gt;::type()); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8409 Trac 1.4.3 Neil Groves Wed, 26 Feb 2014 22:05:38 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8409#comment:1 https://svn.boost.org/trac10/ticket/8409#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> This already exists in the boost/range/algorithm_ext/copy_n.hpp file </p> Ticket