std::move_backward in C++ Last Updated : 20 Jul, 2017 Summarize Comments Improve Suggest changes Share Like Article Like Report Moves the elements in the range [first,last] starting from the end into the range terminating at result. The function begins by moving *(last-1) into *(result-1), and then follows backward by the elements preceding these, until first is reached (and including it). Template : BidirectionalIterator2 move_backward (BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result); result Bidirectional iterator to the past-the-end position in the destination sequence. This shall not point to any element in the range [first,last]. Return Type : An iterator to the first element of the destination sequence where elements have been moved. Examples: Input : vec1 contains : 3 4 5 7 8 vec2 contains : 8 9 6 2 4 7 Output : arr2 contains : 8 9 6 5 7 8 /*3 elements from 3rd position of vector vec1 moved to starting 4th position of vec2*/ CPP // CPP program to illustrate // std::move and std::move_backward // STL library functions #include<bits/stdc++.h> // Driver code int main() { std :: vector <int> vec1 {1, 2, 3, 4, 5}; std :: vector <int> vec2 {7, 7, 7, 7, 7}; // Print elements std :: cout << "Vector1 contains :"; for(int i = 0; i < vec1.size(); i++) std :: cout << " " << vec1[i]; std :: cout << "\n"; // Print elements std :: cout << "Vector2 contains :"; for(unsigned int i = 0; i < vec2.size(); i++) std :: cout << " " << vec2[i]; std :: cout << "\n\n"; // std :: move_backward function std :: move_backward (vec2.begin(), vec2.begin() + 3, vec1.begin() + 3); // Print elements std :: cout << "Vector1 contains after std::move_backward function:"; for(unsigned int i = 0; i < vec1.size(); i++) std :: cout << " " << vec1[i]; std :: cout << "\n"; return 0; } Output: Vector1 contains : 1 2 3 4 5 Vector2 contains : 7 7 7 7 7 Vector1 contains after std::move_backward function: 7 7 7 4 5 Comment More infoAdvertise with us Next Article Vector pop_back() in C++ STL K kartik Improve Article Tags : C++ STL cpp-algorithm-library Practice Tags : CPPSTL Similar Reads std::move in C++ std :: move Moves the elements in the range [first,last] into the range beginning at the result. The value of the elements in the [first,last] is transferred to the elements pointed out by the result. After the call, the elements in the range [first,last] are left in an unspecified but valid state. 2 min read std::back_inserter in C++ std::back_inserter constructs a back-insert iterator that inserts new elements at the end of the container to which it is applied. It is defined inside the header file . A back-insert iterator is a special type of output iterator designed to allow algorithms that usually overwrite elements (such as 4 min read std::forward in C++ In C++, std::forward() is a template function used for achieving perfect forwarding of arguments to functions so that it's lvalue or rvalue is preserved. It basically forwards the argument while preserving the value type of it.std::forward() was introduced in C++ 11 as the part of <utility> he 2 min read Vector back() in C++ STL In C++, the vector back() is a built-in function used to retrieve the last element of the vector. It provides a reference to the last element which allows us to read or modify it directly.Letâs take a quick look at a simple example that illustrates the vector back() method:C++#include <bits/stdc+ 2 min read Vector pop_back() in C++ STL In C++, the vector pop_back() is a built-in method used to remove the last element from a vector. It reduces the size of the vector by one, but the capacity remains unchanged.Letâs take a look at an example that illustrates the vector pop_back() method:C++#include <bits/stdc++.h> using namespa 3 min read std::move_iterator in C++ 11 std::move_iterator was introduced in C++11, with the ability to convert regular iterators into move iterators. Instead of copying, the std::move_iterator allows the STL to move the objects it manipulates. The move iterator wraps the other iterator. This is particularly helpful while working with hug 3 min read Like