Reputation: 12249
Does it make sense that the std::move_iterator
adaptor just inherits the iterator category of the template parameter Iterator type?
Because forward iterators requires that the reference type is of cv-T&
, however, for forward iterator templates, the std::move_iterator<It>::reference
will be an r-value reference to the Iterator's value type (with the reference qualifiers preserved).
Upvotes: 2
Views: 59
Reputation: 473262
Because forward iterators requires that the reference type is of cv-T&, however
Incorrect. The standard (C++17, N4659, [forward.iterators]/1.3) says:
if
X
is a mutable iterator,reference
is a reference toT
; ifX
is a constant iterator,reference
is a reference to constT
Rvalue references are a "reference to T
". Therefore, they qualify. If they meant to exclude rvalue references, the standard would have said "lvalue reference to T
".
So it's perfectly valid for a ForwardIterator to return an rvalue reference.
Upvotes: 5