Is decltype(*it) the value type of the iterator, or an lvalue reference to that, or something else?
I think it is an lvalue reference, because *it is an lvalue, but I’m not sure.
Note: In my case, it is a BidirectionalIterator, but feel free to answer the general case.
*itis not necessarily an lvalue. Only forward iterators have that requirement.Iterators (§24.2.2) are required to have
*itbe a valid expression that returnsiterator_traits<Iterator>::reference(and other irrelevant things). Nothing else is said about this andreferencedoes not have to be a reference type†.Input iterators (§24.2.3) are required to have
*itbe a valid expression that returns something convertible to the value type.Forward iterators, however, have the following requirement (§24.2.5 paragraph 1):
(here
Tis the iterator’s value type)This requires
*itto be a reference, which means it has to be a glvalue (i.e. cannot be a prvalue but can be an xvalue like it is the case with move iterators).The higher iterator categories do not add any relevant requirements.
†
referenceis defined to be the type of*itwhich makes it a bit of a circular definition, but poses no restrictions.