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

libstdc++: Handle integer-class types as bounds for repeat_view

Enables `repeat_view` to correctly use integer-like types as bounds, fixing issues with unsigned types and difference type calculation.

This change updates std::ranges::repeat_view to properly handle integer-like types, including unsigned ones, as bounds for the range. Previously, unsigned integer types were rejected because they did not meet certain C++20 concepts, and the calculation of the difference type was flawed for these bounds. This fix implements LWG 3875, ensuring that repeat_view behaves correctly with a wider range of integer types.

In Details

This commit modifies std::ranges::repeat_view and its iterator to correctly handle bounds that are integer-class types, addressing LWG 3875. The primary issue was that iter_difference_t is not defined for all integer-class types, leading to rejection of unsigned types. The difference_type definition is updated to avoid instantiating __iota_diff_t for all signed integer-like types. The iterator's constraints are updated to accommodate these types, and _S_difference_type is defined using a concept that ensures usable difference types, aligning with the standard's intent.

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.
bound
In the context of C++ ranges, a bound refers to the end of a range, which can be an iterator or a sentinel value.
integer-class types
Types that behave like integers but may have different underlying representations or semantics, often used in template metaprogramming or for specific numeric traits.
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++20rangesiteratorconcepts