GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::copy_backward(3) C++ Standard Libary std::copy_backward(3)

std::copy_backward - std::copy_backward


Defined in header <algorithm>
template< class BidirIt1, class BidirIt2 >
BidirIt2 copy_backward( BidirIt1 first, BidirIt1 last, BidirIt2 (until C++20)
d_last );
template< class BidirIt1, class BidirIt2 >
constexpr BidirIt2 copy_backward( BidirIt1 first, BidirIt1 last, (since C++20)
BidirIt2 d_last );


Copies the elements from the range, defined by [first, last), to another range
ending at d_last. The elements are copied in reverse order (the last element is
copied first), but their relative order is preserved.


The behavior is undefined if d_last is within (first, last]. std::copy must be used
instead of std::copy_backward in that case.


first, last - the range of the elements to copy from
d_last - the end of the destination range


-
BidirIt must meet the requirements of LegacyBidirectionalIterator.


iterator to the last element copied.


Exactly last - first assignments.


When copying overlapping ranges, std::copy is appropriate when copying to the left
(beginning of the destination range is outside the source range) while
std::copy_backward is appropriate when copying to the right (end of the destination
range is outside the source range).


template< class BidirIt1, class BidirIt2 >
BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last)
{
while (first != last) {
*(--d_last) = *(--last);
}
return d_last;
}

// Run this code


#include <algorithm>
#include <iostream>
#include <vector>


int main()
{
std::vector<int> from_vector;
for (int i = 0; i < 10; i++) {
from_vector.push_back(i);
}


std::vector<int> to_vector(15);


std::copy_backward(from_vector.begin(), from_vector.end(), to_vector.end());


std::cout << "to_vector contains: ";
for (auto i: to_vector) {
std::cout << i << " ";
}
}


to_vector contains: 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9


copy copies a range of elements to a new location
copy_if (function template)
(C++11)
ranges::copy_backward copies a range of elements in backwards order
(C++20) (niebloid)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.