function template
<algorithm>
std::copy_backwardtemplate <class BidirectionalIterator1, class BidirectionalIterator2> BidirectionalIterator2 copy_backward (BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result);
Copy range of elements backward
Copies the elements in the range[first,last)
starting from the end into the range terminating at result.
The function returns an iterator to the first element in the destination range.
The resulting range has the elements in the exact same order as [first,last)
. To reverse their order, see reverse_copy.
The function begins by copying *(last-1)
into *(result-1)
, and then follows backward by the elements preceding these, until first is reached (and including it).
The ranges shall not overlap in such a way that result (which is the past-the-end element in the destination range) points to an element in the range (first,last]
. For such cases, see copy.
The behavior of this function template is equivalent to:
1
2
3
4
5
6
7
8
template<class BidirectionalIterator1, class BidirectionalIterator2>
BidirectionalIterator2 copy_backward ( BidirectionalIterator1 first,
BidirectionalIterator1 last,
BidirectionalIterator2 result )
{
while (last!=first) *(--result) = *(--last);
return result;
}
[first,last)
, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
(first,last]
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// copy_backward example
#include <iostream> // std::cout
#include <algorithm> // std::copy_backward
#include <vector> // std::vector
int main () {
std::vector<int> myvector;
// set some values:
for (int i=1; i<=5; i++)
myvector.push_back(i*10); // myvector: 10 20 30 40 50
myvector.resize(myvector.size()+3); // allocate space for 3 more elements
std::copy_backward ( myvector.begin(), myvector.begin()+5, myvector.end() );
std::cout << "myvector contains:";
for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
myvector contains: 10 20 30 10 20 30 40 50
[first,last)
are accessed (each object is accessed exactly once).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4