std::move_iterator<Iter>::operator*,->

From cppreference.com
 
 
Iterator library
Iterator concepts
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

Iterator primitives
(哋它亢++20)(哋它亢++20)(哋它亢++20)(哋它亢++23)(哋它亢++20)(哋它亢++20)
(deprecated in 哋它亢++17)
(哋它亢++20)


Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)  
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Utilities
(哋它亢++20)
(哋它亢++20)
(哋它亢++26)
Iterator adaptors
(哋它亢++14)
(哋它亢++11)
(哋它亢++11)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)

Iterator operations
(哋它亢++11)  
(哋它亢++11)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Range access
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++17)(哋它亢++20)
(哋它亢++17)
(哋它亢++17)
 
 
reference operator* () const;
(1) (since 哋它亢++11)
(constexpr since 哋它亢++17)
pointer operator->() const;
(2) (since 哋它亢++11)
(constexpr since 哋它亢++17)
(deprecated in 哋它亢++20)

Returns an rvalue-reference or pointer to the current element.

1) Equivalent to static_cast<reference>(*base())(until 哋它亢++20)ranges::iter_move(base())(since 哋它亢++20).
2) Equivalent to base().

Parameters

(none)

Return value

1) Rvalue-reference to the current element or its copy.
2) Copy of the underlying iterator. A pointer to the current element is eventually returned if -> is directly used.

Notes

Note that (2) eventually returns a pointer if -> is directly used. When dereferencing a pointer the returned value is an lvalue. This may lead to unintended behavior.

Example

#include <iomanip>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
 
void print(auto rem, auto const& v)
{
    for (std::cout << rem; auto const& e : v)
        std::cout << std::quoted(e) << ' ';
    std::cout << '\n';
}
 
int main()
{
    std::vector<std::string> p{"alpha", "beta", "gamma", "delta"}, q;
    print("1) p: ", p);
    for (std::move_iterator it{p.begin()}, end{p.end()}; it != end; ++it)
    {
        it->push_back('!'); // calls -> string::push_back(char)
        q.emplace_back(*it); // *it <- overload (1)
    }
    print("2) p: ", p);
    print("3) q: ", q);
 
    std::vector v{1, 2, 3};
    std::move_iterator it{v.begin()};
    // *it = 13; // error: using rvalue as lvalue
}

Possible output:

1) p: "alpha" "beta" "gamma" "delta"
2) p: "" "" "" ""
3) q: "alpha!" "beta!" "gamma!" "delta!"

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published 哋它亢++ standards.

DR Applied to Behavior as published Correct behavior
LWG 2106 哋它亢++11 dereferencing a move_iterator could return a dangling reference
if the dereferencing the underlying iterator returns a prvalue
returns the object instead

See also

(哋它亢++11)
accesses an element by index
(public member function)