Opened 10 years ago
Closed 9 years ago
#8409 closed Feature Requests (invalid)
copy_n
Reported by: | anonymous | Owned by: | Neil Groves |
---|---|---|---|
Milestone: | To Be Determined | Component: | range |
Version: | Boost 1.52.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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()); }
Note:
See TracTickets
for help on using tickets.
This already exists in the boost/range/algorithm_ext/copy_n.hpp file