description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ms.custom | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: move_iterator Class |
move_iterator Class |
06/17/2022 |
|
|
a5e5cdd8-a264-4c6b-9f9c-68b0e8edaab7 |
devdivchpfy22 |
Class template move_iterator
is a wrapper for an iterator. The move_iterator provides the same behavior as the iterator it wraps (stores), except it turns the stored iterator's dereference operator into an rvalue reference, turning a copy into a move. For more information about rvalues, see Rvalue Reference Declarator: &&.
class move_iterator;
The class template describes an object that behaves like an iterator except when dereferenced. It stores a random-access iterator of type Iterator
, accessed by way of the member function base()
. All operations on a move_iterator
are performed directly on the stored iterator, except that the result of operator*
is implicitly cast to value_type&&
to make an rvalue reference.
A move_iterator
might be capable of operations that aren't defined by the wrapped iterator. These operations shouldn't be used.
Constructor | Description |
---|---|
move_iterator | The constructor for objects of type move_iterator . |
Type name | Description |
---|---|
iterator_type | A synonym for the template parameter RandomIterator . |
iterator_category | A synonym for a longer typename expression of the same name, iterator_category identifies the general abilities of the iterator. |
value_type | A synonym for a longer typename expression of the same name, value_type describes what type the iterator elements are. |
difference_type | A synonym for a longer typename expression of the same name, difference_type describes the integral type required to express difference values between elements. |
pointer | A synonym for template parameter RandomIterator . |
reference | A synonym for the rvalue reference value_type&& . |
Member function | Description |
---|---|
base | The member function returns the stored iterator wrapped by this move_iterator . |
Operator | Description |
---|---|
move_iterator::operator* | Returns (reference)*base(). |
move_iterator::operator++ | Increments the stored iterator. Exact behavior depends on whether it's a preincrement or a postincrement operation. |
move_iterator::operator-- | Decrements the stored iterator. Exact behavior depends on whether it's a predecrement or a postdecrement operation. |
move_iterator::operator-> |
Returns &**this . |
move_iterator::operator- | Returns move_iterator(*this) -= by first subtracting the right-hand value from the current position. |
move_iterator::operator[] | Returns (reference)*(*this + off) . Allows you to specify an offset from the current base to obtain the value at that location. |
move_iterator::operator+ | Returns move_iterator(*this) += the value. Allows you to add an offset to the base to obtain the value at that location. |
move_iterator::operator+= | Adds the right-hand value to the stored iterator, and returns *this . |
move_iterator::operator-= | Subtracts the right-hand value from the stored iterator, and returns *this . |
Header: <iterator>
Namespace: std
Returns the stored iterator for this move_iterator
.
RandomIterator base() const;
The member function returns the stored iterator.
The type difference_type
is a move_iterator
typedef
based on the iterator trait difference_type
, and can be used interchangeably with it.
typedef typename iterator_traits<RandomIterator>::difference_type difference_type;
The type is a synonym for the iterator trait typename iterator_traits<RandomIterator>::pointer
.
The type iterator_category
is a move_iterator
typedef
based on the iterator trait iterator_category
, and can be used interchangeably with it.
typedef typename iterator_traits<RandomIterator>::iterator_category iterator_category;
The type is a synonym for the iterator trait typename iterator_traits<RandomIterator>::iterator_category
.
The type iterator_type
is based on the template parameter RandomIterator
for the class template move_iterator
, and can be used interchangeably in its place.
typedef RandomIterator iterator_type;
The type is a synonym for the template parameter RandomIterator
.
Constructs a move iterator. Uses the parameter as the stored iterator.
move_iterator();
explicit move_iterator(RandomIterator right);
template <class Type>
move_iterator(const move_iterator<Type>& right);
right
The iterator to use as the stored iterator.
The first constructor initializes the stored iterator with its default constructor. The remaining constructors initialize the stored iterator with base.base()
.
Adds an offset to the stored iterator, so that the stored iterator points to the element at the new current location. The operator then moves the new current element.
move_iterator& operator+=(difference_type _Off);
_Off
An offset to add to the current position to determine the new current position.
Returns the new current element.
The operator adds _Off to the stored iterator. Then returns *this
.
Moves across a specified number of previous elements. This operator subtracts an offset from the stored iterator.
move_iterator& operator-=(difference_type _Off);
The operator evaluates *this += -_Off
. Then returns *this
.
Increments the stored iterator that belongs to this move_iterator
. The current element is accessed by the postincrement operator. The next element is accessed by the preincrement operator.
move_iterator& operator++();
move_iterator operator++(int);
The first (preincrement) operator increments the stored iterator. Then returns *this
.
The second (postincrement) operator makes a copy of *this
, evaluates ++*this
. Then returns the copy.
Returns the iterator position advanced by any number of elements.
move_iterator operator+(difference_type _Off) const;
The operator returns move_iterator(*this) +=
_Off
.
Allows array index access to elements across the range of the move iterator
.
reference operator[](difference_type _Off) const;
The operator returns (reference)*(*this + _Off)
.
Pre- and postdecrement member operators perform a decrement on the stored iterator.
move_iterator& operator--();
move_iterator operator--();
The first member operator (predecrement) decrements the stored iterator. Then returns *this
.
The second (postdecrement) operator makes a copy of *this
, evaluates --*this
. Then returns the copy.
Decrements the stored iterator and returns the indicated value.
move_iterator operator-(difference_type _Off) const;
The operator returns move_iterator(*this) -= _Off
.
Dereferences the stored iterator and returns the value. This behaves like an rvalue reference
and performs a move assignment. The operator transfers the current element out of the base iterator. The element that follows becomes the new current element.
reference operator*() const;
The operator returns (reference)*base()
.
Like a normal RandomIterator
operator->
, it provides access to the fields that belong to the current element.
pointer operator->() const;
The operator returns &**this
.
The type pointer
is a typedef
based on the random iterator RandomIterator
for move_iterator
, and can be used interchangeably.
typedef RandomIterator pointer;
The type is a synonym for RandomIterator
.
The type reference
is a typedef
based on value_type&&
for move_iterator
, and can be used interchangeably with value_type&&
.
typedef value_type&& reference;
The type is a synonym for value_type&&
, which is an rvalue reference.
The type value_type
is a move_iterator
typedef
based on the iterator trait value_type
, and can be used interchangeably with it.
typedef typename iterator_traits<RandomIterator>::value_type value_type;
The type is a synonym for the iterator trait typename iterator_traits<RandomIterator>::value_type
.
<iterator>
Lvalues and Rvalues
Move Constructors and Move Assignment Operators (C++)
C++ Standard Library Reference