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

libstdc++: Change piecewise distribution densities to return vector<result_type>.

Updates piecewise distribution densities to return `vector<result_type>` aligning with LWG1439.

This change modifies piecewise_linear_distribution in libstdc++ to return vector<result_type> from its densities() member functions, aligning with the LWG1439 resolution. ABI compatibility is maintained by storing densities in a potentially different _StorageType and converting to result_type on access. New macros are introduced to manage ABI compatibility and to enable unconditional use of result_type for internal storage.

In Details

This commit implements LWG1439, changing the densities() member functions of piecewise_linear_distribution to return std::vector<result_type> instead of std::vector<T> (where T is the template parameter of the distribution). To preserve ABI compatibility, an internal __piecewise_distributions_storage struct is introduced. This struct uses double for extended floating-point types (like __float128) when result_type is distinct, and _Tp otherwise. Existing behavior can be restored with _GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS, and a new macro `_GLIBCXX_USE_RESULT_TYPE_FOR_PI…

For Context
LWG1439
A specific issue (issue 1439) from the C++ Library Working Group (LWG) that addresses changes to the densities() functions in piecewise_linear_distribution.
ABI compatibility
Application Binary Interface compatibility ensures that code compiled with one version of a library can still interact with code compiled with another version, even if internal data structures have changed.
result_type
In the context of piecewise_linear_distribution, this is the type used for the distribution's generated values, often double or float.
densities()
A member function of piecewise_linear_distribution that returns the probability densities of the discrete intervals defining the distribution.
Filed Under: libstdc++randomcppabi