Javatpoint Logo
Javatpoint Logo

C++ Algorithm Function move ()

C++ Algorithm move()function is used for moving the elements. It accepts three arguments and then moves the elements belonging to the range [first,last) into a range that starts with 'result'.



first: It is an input iterator to the first element of the range, where the element itself is included in the range.

last: It is an input iterator to the last element of the range, where the element itself is not included in the range.

result: It is an output iterator to the initial position of the moved elements.

Return value

The function returns an iterator of the first element to the sequence of moved ones.

Example 1


Move function.
a contains 4 elements: (The state of which is valid.)
b contains 4 elements: [suraj] [aman] [vanshika] [chhavi]
Moving the conatiner a...
a contains 4 elements: [suraj] [aman] [vanshika] [chhavi]
b is in valid state

Example 2


u1 contains : 9 14 21 18
u2 contains : 14 14 14 14

u2 contains after move function: 14 9 14 21


The complexity of the function is linear starting from the first element to the last one.

Data races

Some or all of the container objects are accessed.


The function throws an exception if any of the container elements throws one.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA