| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Non-modifying sequence operations | |||||||||||||||||||||||||||||||||
| Modifying sequence operations | |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| Partitioning operations | |||||||||||||||||||||||||||||||||
| Sorting operations | |||||||||||||||||||||||||||||||||
| Binary search operations | |||||||||||||||||||||||||||||||||
| Set operations (on sorted ranges) | |||||||||||||||||||||||||||||||||
| Heap operations | |||||||||||||||||||||||||||||||||
| Minimum/maximum operations | |||||||||||||||||||||||||||||||||
| Permutations | |||||||||||||||||||||||||||||||||
Defined in header <experimental/ranges/algorithm> | ||
template< InputIterator I, Sentinel<I> S, WeaklyIncrementable O> requires IndirectlyCopyable<I, O> | (1) | (ranges TS) |
template< InputRange R, WeaklyIncrementable O> requires IndirectlyCopyable<ranges::iterator_t<R>, O> | (2) | (ranges TS) |
template< InputIterator I, Sentinel<I> S, WeaklyIncrementable O, class Proj=ranges::identity, | (3) | (ranges TS) |
template< InputRange R, WeaklyIncrementable O, class Proj=ranges::identity, | (4) | (ranges TS) |
Copies elements in the source range ([first, last) orr) into the destination range beginning atresult, starting from the first element in the source range and proceeding to the last one.
[first, last). For each non-negative integern < (last - first), performs*(result+ n)=*(first+ n). The behavior is undefined ifresult is within the range[first, last). In this case,ranges::copy_backward may be used instead.Notwithstanding the declarations depicted above, the actual number and order of template parameters for algorithm declarations is unspecified. Thus, if explicit template arguments are used when calling an algorithm, the program is probably non-portable.
Contents |
| first, last | - | the range of elements to copy |
| r | - | the range of elements to copy |
| result | - | the beginning of the destination range |
| pred | - | predicate to apply to the projected elements |
| proj | - | projection to apply to the elements |
Atagged_pair object containing the following two members:
tag::in, is the past-the-end iterator of the source range (that is, an iterator of typeI that compares equal to the sentinellast).tag::out, is the past-the-end iterator of the result range.| First version |
|---|
template<InputIterator I, Sentinel<I> S, WeaklyIncrementable O> requires IndirectlyCopyable<I, O>()ranges::tagged_pair<tag::in(I),tag::out(O)> copy(I first, S last, O result){for(; first!= last;++first,(void)++result)*result=*first;return{first, result};} |
| Second version |
template<InputRange R, WeaklyIncrementable O> requires IndirectlyCopyable<ranges::iterator_t<R>, O>()ranges::tagged_pair<tag::in(ranges::safe_iterator_t<R>),tag::out(O)> copy(R&& r, O result){returnranges::copy(ranges::begin(r),ranges::end(r), result);} |
| Third version |
template<InputIterator I, Sentinel<I> S, WeaklyIncrementable O,class Proj=ranges::identity, IndirectUnaryPredicate<projected<I, Proj>> Pred> requires IndirectlyCopyable<I, O>()ranges::tagged_pair<tag::in(I),tag::out(O)> copy_if(I first, S last, O result, Pred pred, Proj proj= Proj{}){for(; first!= last;++first)if(ranges::invoke(pred,ranges::invoke(proj,*first))){*result=*first;++result;}return{first, result};} |
| Fourth version |
template<InputRange R, WeaklyIncrementable O,class Proj=ranges::identity, IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred> requires IndirectlyCopyable<ranges::iterator_t<R>, O>()ranges::tagged_pair<tag::in(ranges::safe_iterator_t<R>),tag::out(O)> copy_if(R&& r, O result, Pred pred, Proj proj= Proj{}){returnranges::copy_if(ranges::begin(r),ranges::end(r), result, pred, proj);} |
The following code uses copy to both copy the contents of one vector to another and to display the resulting vector:
#include <experimental/ranges/algorithm>#include <experimental/ranges/iterator>#include <iostream>#include <numeric>#include <vector> int main(){// see https://en.cppreference.com/w/cpp/language/namespace_aliasnamespace ranges= std::experimental::ranges; std::vector<int> from_vector(10);std::iota(from_vector.begin(), from_vector.end(),0); std::vector<int> to_vector;ranges::copy_if(from_vector.begin(), from_vector.end(), ranges::back_inserter(to_vector),[](constauto i){return i%3;});// or, alternatively,// std::vector<int> to_vector(from_vector.size());// std::copy(from_vector, to_vector.begin()); std::cout<<"to_vector contains: "; ranges::copy(to_vector, ranges::ostream_iterator<int>(std::cout," "));std::cout<<'\n';}
Output:
to_vector contains: 1 2 4 5 7 8
(C++11) | copies a range of elements to a new location (function template)[edit] |
| copies a range of elements in backwards order (function template)[edit] | |
| creates a copy of a range that is reversed (function template)[edit] | |
| copies a number of elements to a new location (function template)[edit] | |
| assigns a range of elements a certain value (function template)[edit] | |
| copies a range of elements omitting those that satisfy specific criteria (function template)[edit] |