[Boost-bugs] [Boost C++ Libraries] #8409: copy_n

Subject: [Boost-bugs] [Boost C++ Libraries] #8409: copy_n
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-04-06 12:43:05


#8409: copy_n
------------------------------+---------------------------------------------
 Reporter: anonymous | Owner: neilgroves
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost 1.52.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 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.

 {{{
 if(copy_n(range,size,out) != out+size) throw something;
 }}}

 {{{
 template<class Range,class Size,class OutputIterator>
 OutputIterator copy_n(Range const &r,Size s,OutputIterator const
 &out,std::random_access_iterator_tag){
     if(s <= size(r) return range_copy(r,out);
     else return out;
 }

 template<class Range,class Size,class OutputIterator,class InCat>
 OutputIterator copy_n(Range const &r,Size s,OutputIterator out,InCat){
     typename range_const_iterator<Range>::type it=begin(r);
     for(std::size_t c=0;c<s && it != end(r);++c){
         *out++=*it++;
     }
     return out;
 }


 template<class Range,class Size,class OutputIterator>
 OutputIterator copy_n(Range const &r,Size size,OutputIterator const &out){
     return detail::copy_n(r,size,out,typename
 range_category<Range>::type());
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8409>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC