C++C++11C++14C++17Iterators

The Move Iterator Adapter in C++

The dereference prefix operator * being applied to iterator returns the lvalue reference to the element pointed by the iterator. Therefore, algorithms such as std::copy or std::transform calls copying constructors of processed elements, for example:

However it’s possible to force algorithms to call moving constructors when it’s appropriate for performance reasons by using the special adapter called std::move_iterator provided by the standard library. This adapter class defines the dereference operator * in such a way that it returns the rvalue (rather than lvalue) reference to the element pointer by the iterator. The object of type std::move_iterator can be conveniently created by the function std::make_move_iterator that deduces the underlying type of the iterator object from it’s argument automatically, for example:

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?