Share via


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.

Requirements

Header: <iterator>

Namespace: std

See Also

Tasks

How to: Write a Move Constructor

Reference

Lvalues and Rvalues

Standard Template Library

Other Resources

<iterator> Members