Freigeben über


move_iterator Class

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: &&.

template<class Iterator>
    class move_iterator {
public:
    typedef Iterator iterator_type;
    typedef typename    
        iterator_traits<Iterator>::iterator_category
            iterator_category;
    typedef typename iterator_traits<Iterator>::value_type
        value_type;
    typedef typename iterator_traits<Iterator>::difference_type
        difference_type;
    typedef Iterator
        pointer;
    typedef value_type&&
        reference;

    move_iterator();
    explicit move_iterator (Iterator right);
    template<class Type>
        move_iterator (const move_iterator<Type>& right);
    template <class Type> 
        move_iterator& operator=(const move_iterator<Type>& right);

    iterator_type base () const;
    reference operator* () const;
    pointer operator-> () const;

    move_iterator& operator++ ();
    move_iterator operator++ (int);
    move_iterator& operator-- ();
    move_iterator operator-- (int);

    move_iterator& operator+= (difference_type off);
    move_iterator operator+ (difference_type off) const;
    move_iterator& operator-= (difference_type off);
    move_iterator operator- (difference_type off) const;
    reference operator[] (difference_type off) const;
    };

Remarks

The template class 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 are not defined by the wrapped iterator. These operations should not be used.

Constructors

move_iterator

The constructor for objects of type move_iterator.

Typedefs

move_iterator::iterator_type

A synonym for the template parameter RandomIterator.

move_iterator::iterator_category

A synonym for a longer typename expression of the same name, iterator_category identifies the general abilities of the iterator.

move_iterator::value_type

A synonym for a longer typename expression of the same name, value_type describes what type the iterator elements are.

move_iterator::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.

move_iterator::pointer

A synonym for template parameter RandomIterator.

move_iterator::reference

A synonym for the rvalue reference value_type&&.

Member Functions

move_iterator::base

The member function returns the stored iterator wrapped by this move_iterator.

Operators

move_iterator::operator*

Returns (reference)*base().

move_iterator::operator++

Increments the stored iterator. Exact behavior depends on whether it is a preincrement or a postincrement operation.

move_iterator::operator--

Decrements the stored iterator. Exact behavior depends on whether it is 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.

Requirements

Header: <iterator>

Namespace: std

See Also

Tasks

How to: Write a Move Constructor

Reference

<iterator>

Lvalues and Rvalues

Standard Template Library