GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

libstdc++: Add begin, end, (const_)iterator members to valarray.

Implements P3016R6 by adding iterator support to `std::valarray` in libstdc++.

The std::valarray class in libstdc++ now supports iterators via the begin() and end() member functions, as well as iterator and const_iterator typedefs. This implementation is based on sections 4.3, 4.4, and 4.5 of P3016R6, and is enabled when __glibcxx_valarray >= 202511L. A new test case verifies the functionality.

In Details

This commit modifies include/std/valarray and include/bits/range_access.h within the libstdc++-v3 repository. It introduces valarray::begin(), valarray::end(), valarray::iterator, and valarray::const_iterator, guarded by __glibcxx_valarray. It also conditionally defines std::begin and std::end for valarray in namespace std, forwarding to the member functions. This is related to P3016R6, which proposes adding iterator support to valarray.

For Context

std::valarray is a C++ standard library class designed for efficient numerical computation on arrays of values. Iterators are a general mechanism in C++ to access elements of containers (like std::vector or std::list) in a sequential manner. This commit adds iterator support to std::valarray, making it easier to use valarray with range-based for loops and other algorithms that rely on iterators. It implements a proposal that brings valarray in line with other standard containers.

Filed Under: libstdc++valarrayiteratorsC++23