std::copy
<algorithm>
template <class InputIterator, class OutputIterator> OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result );
Copy range of elements
Copies the elements in the range
[first,last)
into a range beginning at
result
.
Returns an iterator to the end of the destination range (which points to the element following the copy of last ).
The behavior of this function template is equivalent to:
| |
std::copy_backward
<algorithm>
template <class BidirectionalIterator1, class BidirectionalIterator2> BidirectionalIterator2 copy_backward ( BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result );
Copy range of elements backwards
Copies the elements in the range
[first,last)
into a range whose end element is
result
. The function begins by copying
*(last-1)
into
*(result-1)
, and then follows backwards by the elements preceeding these, until
first
is reached (and including it).
Returns an iterator to the first element in the destination range.
The behavior of this function template is equivalent to:
| |
std::swap
<algorithm>
template <class T> void swap ( T& a, T& b );
Exchange values of two objects
Assigns the content of
a
to
b
and the content of
b
to
a
.
The behavior of this function template is equivalent to:
| |
std::swap_ranges
<algorithm>
template < class ForwardIterator1, class ForwardIterator2 > ForwardIterator2 swap_ranges ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2 );
Exchange values of two ranges
Swaps the values of each of the elements in the range
[first1,last1)
with those of their respective elements in the range beginning at
first2
.
The behavior of this function template is equivalent to:
| |
std::iter_swap
<algorithm>
template <class ForwardIterator1, class ForwardIterator2> void iter_swap ( ForwardIterator1 a, ForwardIterator2 b );
Exchange values of objects pointed by two iterators
Assigns the content of
*a
to
*b
and the content of
*b
to
*a
.
The behavior of this function template is equivalent to:
| |
std::transform
<algorithm>
template < class InputIterator, class OutputIterator, class UnaryOperator > OutputIterator transform ( InputIterator first1, InputIterator last1, OutputIterator result, UnaryOperator op ); template < class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperator > OutputIterator transform ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperator binary_op );
Apply function to range
The first version applies
op
to all the elements in the input range (
[first1,last1)
) and stores each returned value in the range beginning at
result
.
The second version uses as argument for each call to binary_op one element from the first input range ( [first1,last1) ) and one element from the second input range (beginning at first2 ).
The behavior of this function template is equivalent to:
| |
std::replace
<algorithm>
template < class ForwardIterator, class T > void replace ( ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value );
Replace value in range
Sets all the elements in the range
[first,last)
whose current value equals
old_value
to a value of
new_value
.
The behavior of this function template is equivalent to:
| |
std::replace_if
<algorithm>
template < class ForwardIterator, class Predicate, class T > void replace_if ( ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value );
Replace values in range
Sets all those elements in the range
[first,last)
for which
pred
returns
true
when applied to its value, to a value of
new_value
.
The behavior of this function template is equivalent to:
| |
std::replace_copy
<algorithm>
template < class InputIterator, class OutputIterator, class T > OutputIterator replace_copy ( InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value );
Copy range replacing value
Copies the values of the elements in the range
[first,last)
to the range positions beginning at
result
, replacing the appearances of
old_value
by
new_value
.
The behavior of this function template is equivalent to:
| |
std::replace_copy_if
<algorithm>
template < class InputIterator, class OutputIterator, class Predicate, class T > OutputIterator replace_copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value );
Copy range replacing value
Copies the values of the elements in the range
[first,last)
to the range positions beginning at location pointed by
result
, replacing those where
pred
is true by
new_value
.
The behavior of this function template is equivalent to:
| |
std::fill
<algorithm>
template < class ForwardIterator, class T > void fill ( ForwardIterator first, ForwardIterator last, const T& value );
Fill range with value
Sets
value
to all elements in the range
[first,last)
.
The behavior of this function template is equivalent to:
| |
std::fill_n
<algorithm>
template < class OutputIterator, class Size, class T > void fill_n ( OutputIterator first, Size n, const T& value );
Fill sequence with value
Sets
value
to the first
n
elements in the sequence pointed by
first
.
The behavior of this function template is equivalent to:
| |
function template
std::generate
<algorithm>
template <class ForwardIterator, class Generator> void generate ( ForwardIterator first, ForwardIterator last, Generator gen );
Generate values for range with function
Sets the value of the elements in the range
[first,last)
to the value returned by successive calls to
gen
.
The behavior of this function template is equivalent to:
| |
std::generate_n
<algorithm>
template <class OutputIterator, class Size, class Generator> void generate_n ( OutputIterator first, Size n, Generator gen );
Generate values for sequence with function
Sets the value of the first
n
elements in the sequence pointed by
first
to the value returned by successive calls to
gen
.
The behavior of this function template is equivalent to:
| |
std::remove
<algorithm>
template < class ForwardIterator, class T > ForwardIterator remove ( ForwardIterator first, ForwardIterator last, const T& value );
Remove value from range
Compares the elements in the range
[first,last)
against
value
, and removes those that compare equal from the resulting range. The resulting range consists of the elements between
first
and the iterator returned by the function, which points to the new end of the range.
The relative order of the elements not removed is preserved, while the elements past the new end of range are still valid, although with unspecified values.
The behavior of this function template is equivalent to:
| |
std::remove_if
<algorithm>
template < class ForwardIterator, class Predicate > ForwardIterator remove_if ( ForwardIterator first, ForwardIterator last, Predicate pred );
Remove elements from range
Applies
pred
to the elements in the range
[first,last)
, and removes those for which it does not return
false
from the resulting range. The resulting range consists of the elements between
first
and the iterator returned by the function, which points to the new end of the range.
The relative order of the elements not removed is preserved, while the elements past the new end of range are still valid, although with unspecified values.
The behavior of this function template is equivalent to:
| |
std::remove_copy
<algorithm>
template <class InputIterator, class OutputIterator, class T> OutputIterator remove_copy ( InputIterator first, InputIterator last, OutputIterator result, const T& value );
Copy range removing value
Copies the values of the elements in the range
[first,last)
to the range positions beginning at
result
, except for the elements that compare equal to
value
, which are not copied.
The behavior of this function template is equivalent to:
| |
std::remove_copy_if
<algorithm>
template <class InputIterator, class OutputIterator, class Predicate> OutputIterator remove_copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate pred );
Copy range removing values
Copies the values of the elements in the range
[first,last)
to the range positions beginning at
result
, except those for which
pred
is true, which are not copied.
The behavior of this function template is equivalent to:
| |
std::unique
<algorithm>
template <class ForwardIterator> ForwardIterator unique ( ForwardIterator first, ForwardIterator last ); template <class ForwardIterator, class BinaryPredicate> ForwardIterator unique ( ForwardIterator first, ForwardIterator last, BinaryPredicate pred );
Remove consecutive duplicates in range
Removes the duplicate consecutive elements from the range
[first,last)
. This is done by removing from the resulting range all the elements that compare equal to the element right preceding them (only the first element in each group of consecutive equal elements is kept).
The resulting range consists of the elements between first and the iterator returned by the function, which points to the new end of range. The elements past the new end of range are still valid, although with unspecified values.
The comparison between elements is performed by either applying the == comparison operator, or the template parameter comp (for the second version) between them.
The behavior of this function template is equivalent to:
| |
std::unique_copy
<algorithm>
template <class InputIterator, class OutputIterator> OutputIterator unique_copy ( InputIterator first, InputIterator last, OutputIterator result ); template <class InputIterator, class OutputIterator, class BinaryPredicate> OutputIterator unique_copy ( InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred );
Copy range removing duplicates
Copies the values of the elements in the range
[first,last)
to the range positions beginning at
result
, except for the duplicate consecutive elements, which are not copied
The elements not copied are those that compare equal to the element right preceding them (only the first element in each group of consecutive equal elements is copied).
The comparison between elements is performed by either applying the == comparison operator, or the template parameter pred (for the second version) between them.
The behavior of this function template is equivalent to:
| |
std::reverse
<algorithm>
template <class BidirectionalIterator> void reverse ( BidirectionalIterator first, BidirectionalIterator last);
Reverse range
Reverses the order of the elements in the range
[first,last)
.
The behavior of this function template is equivalent to:
| |
std::reverse_copy
<algorithm>
template <class BidirectionalIterator, class OutputIterator> OutputIterator reverse_copy ( BidirectionalIterator first, BidirectionalIterator last, OutputIterator result );
Copy range reversed
Copies the values of the elements in the range [first,last) to the range positions beginning at result, but reversing its order.
The behavior of this function template is equivalent to:
| |
std::rotate
<algorithm>
template <class ForwardIterator> void rotate ( ForwardIterator first, ForwardIterator middle, ForwardIterator last );
Rotate elements in range
Rotates the order of the elements in the range
[first,last)
, in such a way that the element pointed by
middle
becomes the new first element.
The behavior of this function template is equivalent to:
| |
std::rotate_copy
<algorithm>
template <class ForwardIterator, class OutputIterator> OutputIterator rotate_copy ( ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result );
Copy rotated range
Copies the values of the elements in the range
[first,last)
to the range positions beginning at
result
, but rotating the order of the elements in such a way that the element pointed by
middle
becomes the first element in the resulting range.
The behavior of this function template is equivalent to:
| |
std::random_shuffle
<algorithm>
template <class RandomAccessIterator> void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last ); template <class RandomAccessIterator, class RandomNumberGenerator> void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator& rand );
Rearrange elements in range randomly
Rearranges the elements in the range
[first,last)
randomly.
The function swaps the value of each element with that of some other randomly chosen element. When provided, the function rand chooses which element.
The behavior of this function template is equivalent to:
| |
std::partition
<algorithm>
template <class BidirectionalIterator, class Predicate> BidirectionalIterator partition ( BidirectionalIterator first, BidirectionalIterator last, Predicate pred );
Partition range in two
Rearranges the elements in the range
[first,last)
, in such a way that all the elements for which
pred
returns true precede all those for which it returns false. The iterator returned points to the first element of the second group.
The relative ordering within each group is not necessarily the same as before the call. See function stable_partition for a function with a similar behavior and stability in the ordering.
The behavior of this function template is equivalent to:
| |
std::stable_partition
<algorithm>
template <class BidirectionalIterator, class Predicate> BidirectionalIterator stable_partition ( BidirectionalIterator first, BidirectionalIterator last, Predicate pred );
Partition range in two - stable ordering
Rearranges the elements in the range
[first,last)
, in such a way that all the elements for which
pred
returns true precede all those for which it returns false, and, unlike function
partition
, grants the preservation of the relative order of elements within each group.
This is generally implemented using a temporary buffer.
Parameters
-
first, last
- Bidirectional iterators to the initial and final positions of the sequence to be partitioned. The range used is [first,last), which contains all the elements between first and last, including the element pointed by firstbut not the element pointed by last. pred
-
Unary predicate taking an element in the range as argument, and returning a value indicating the falsehood (with
false, or a zero value) or truth (
true, or non-zero) of some condition applied to it. This can either be a pointer to a function or an object whose class overloads
operator().