std::move in C++ Last Updated : 11 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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. Template : OutputIterator move (InputIterator first, InputIterator last, OutputIterator result); Parameters : the first, last Input iterators to the initial and final positions in a sequence to be moved. The range used is [first,last], which contains all the elements between first and last, including the element pointed by first but not the element pointed by last. result Output iterator to the initial position in the destination sequence. This shall not point to any element in the range [first,last]. Return type : An iterator to the end of the destination range where elements have been moved. Examples: Input : vec1 contains : 1 2 3 4 5 vec2 contains : 7 7 7 7 7 Output : arr2 contains : 7 1 2 3 4 /*First 4 elements of vector vec1 moved to vec2 starting second position*/ 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 function // move first 4 element from vec1 to starting position of vec2 std :: move (vec1.begin(), vec1.begin() + 4, vec2.begin() + 1); // Print elements std :: cout << "Vector2 contains after std::move function:"; for(unsigned int i = 0; i < vec2.size(); i++) std :: cout << " " << vec2[i]; std :: cout << "\n"; return 0; } OutputVector1 contains : 1 2 3 4 5 Vector2 contains : 7 7 7 7 7 Vector2 contains after std::move function: 7 1 2 3 4 Time Complexity: O(N) (std::move operation itself takes O(1) time )Auxiliary Space: O(N) Comment More infoAdvertise with us Next Article std::move in C++ S Sachin Bisht Improve Article Tags : C++ STL cpp-algorithm-library Practice Tags : CPPSTL Similar Reads std::prev in C++ std::prev returns an iterator pointing to the element after being advanced by certain number of positions in the reverse direction. It is defined inside the header file iterator. It returns a copy of the argument advanced by the specified amount in the backward direction. If it is a random-access it 5 min read std::next in C++ std::next returns an iterator pointing to the element after being advanced by certain no. of positions. It is defined inside the header file . It does not modify its arguments and returns a copy of the argument advanced by the specified amount. If it is a random-access iterator, the function uses ju 4 min read std::move_backward in C++ 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 m 2 min read std::quoted in C++ 14 std::quoted is an I/O manipulator function that was introduced in C++ 14 as the part of <iomanip> library. Its primary purpose is to handle the quoted string in the input and output operations. In this article, we will learn about the std::quoted manipulator, how it works and how to use it in 5 min read rotate() in C++ STL In C++, rotate() is a built-in function used to rotate the elements of a range in left or right direction such that the element pointed to by a specified iterator becomes the new first element of the range.Let's take a look at an example:C++#include <bits/stdc++.h> using namespace std; int mai 4 min read Like