GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

libstdc++: Extract repeat_view::_Iterator to ranges_util.h

Refactors `repeat_view::_Iterator` into a standalone `_Repeat_iterator` in `bits/ranges_util.h` for better reusability.

The internal iterator for std::ranges::repeat_view has been extracted into a separate class, _Repeat_iterator, in bits/ranges_util.h. This change allows the iterator to be used in other parts of libstdc++ without pulling in the entire std/ranges header. It also enables new overloads for container functions and improves how iterators are constructed and specialized, especially concerning sentinels and difference types.

In Details

This commit extracts repeat_view::_Iterator from std/ranges to bits/ranges_util.h as _Repeat_iterator. This is done to avoid unnecessary dependencies and to facilitate its use in other contexts, such as hive's container function overloads. The standalone _Repeat_iterator is specialized for [__glibcxx_ranges], and its value_type is now correctly const T as repeat_view yields const references. A helper std::__make_repeat_iterator is provided for construction, as the standard-defined constructor is private. The _S_difference_type is updated to use __to_signed_like for b…

For Context
libstdc++
The C++ Standard Library implementation used by GCC.
ranges::repeat_view
A C++20 view that creates a range by repeating a single value a specified number of times.
iterator
An object in C++ that enables traversal through a container or sequence. It typically supports incrementing, dereferencing, and comparison operations.
bits/ranges_util.h
A header file within libstdc++ that contains utility components related to C++20 ranges.
bits/stl_iterator.h
A header file in libstdc++ that defines core iterator concepts and utilities.
LWG
Library Working Group, a committee responsible for evolving the C++ Standard Library.
ptrdiff_t
A signed integer type capable of holding the difference between the pointers to any two elements in the same array.
Filed Under: libstdc++C++20rangesiteratorrefactoring