GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
libstdc++

Libstdc++ asserts layout_stride::mapping uniqueness.

Libstdc++ adds assertions to ensure unique layout_stride::mapping combinations.

Libstdc++ now asserts that the combination of strides and extents passed to layout_stride::mapping is unique. For performance in non-debug builds, only O(rank) checks are performed, while debug builds include an O(rank^2) check using an insertion-sort-based algorithm. This change also ensures consistent behavior for layout_stride mapping construction, aligning with LWG4603.

In Details

The libstdc++ layout_stride::mapping constructor is being updated with assertions to verify the uniqueness of stride and extent combinations. This addresses potential inconsistencies and ensures correct multidimensional array layout representation, especially concerning span conversions and duplicate stride values. Non-debug builds employ a performance-optimized O(rank) check, while debug builds use a more comprehensive O(rank^2) algorithm.

For Context
layout_stride::mapping
A component of the C++ <mdspan> library that defines how multidimensional data is laid out in memory using strides.
strides
Values representing the number of memory elements to skip to move to the next element along a particular dimension in a multidimensional array.
extents
The sizes or dimensions of a multidimensional array.
LWG4603
A specific issue resolution from the C++ Library Working Group that impacts the behavior of multidimensional array layout mapping, ensuring consistent handling of strides and extents.
Filed Under: libstdc++mdspanassertions