GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

libstdc++ uses decltype(auto) for iter_move to support more iterators

libstdc++ iterator adaptors now use `decltype(auto)` for `iter_move`, satisfying LWG 3953 and improving iterator compatibility.

This change in libstdc++ addresses LWG issue 3953 by modifying the iter_move function in iterator adaptors. It replaces rvalue_reference_t<I> with decltype(auto) as the return type. This change ensures that iterators modeling input_or_output_iterator but not input_iterator can be used correctly, as they are no longer required to have a usable iter_rvalue_reference_t, thus improving compatibility and adherence to the C++ standard.

In Details

The libstdc++ implementation of iter_move for common_iterator and counted_iterator is updated to return decltype(auto) instead of std::rvalue_reference_t<I>. This change aligns with the resolution of LWG 3953, relaxing the constraints on iterators. Previously, iterators that did not model input_iterator (e.g., output iterators) but were compatible with common_iterator or counted_iterator would fail to compile if they lacked a suitable iter_rvalue_reference_t. The use of decltype(auto) defers type deduction until initialization, resolving this issue.

For Context
libstdc++
The GNU Standard C++ Library, a widely used implementation of the C++ Standard Library.
iter_move
A utility function in the C++ standard library used to move elements from an iterator's referent. It's designed to work with move semantics.
decltype(auto)
A C++14 feature that allows the return type of a function to be deduced from the type of an expression, while also supporting automatic return type deduction similar to auto.
input_iterator
A type of iterator in C++ that allows sequential access to elements, supporting only input operations (reading elements one by one).
input_or_output_iterator
A C++ iterator concept that is more general than input_iterator, allowing for both input (reading) and output (writing) operations.
LWG 3953
A specific issue resolved by the Library Working Group (LWG) of the C++ standards committee, concerning the iter_move functionality for certain iterator types.
common_iterator
An iterator adapter in C++ that provides a uniform interface to different underlying iterator types, often used to merge ranges.
counted_iterator
An iterator adapter in C++ that represents a range by combining an underlying iterator with a count of elements.
Filed Under: libstdc++c++iteratorstandard library