https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82749

--- Comment #15 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tomasz Kaminski <[email protected]>:

https://gcc.gnu.org/g:eae197924c7ecfe7073914e141941f582cc32828

commit r17-2391-geae197924c7ecfe7073914e141941f582cc32828
Author: Tomasz KamiÅski <[email protected]>
Date:   Tue May 26 15:43:00 2026 +0200

    libstdc++: Change piecewise distribution densities to return
vector<result_type> [PR82749]

    This implements the interface changes from
    LWG1439, "Return from densities() functions?".

    Due the ABI concerns, we cannot change the the element_type of member
    (_M_den, _M_cp, and _M_m) vectors, and we convert the _M_den values
    to result_type when function is invoked. However, as the usage of
    distributions with types other than float, double, and long double
    is either undefined (pre C++26) or implementaiton-defined (post C++26),
    this limitation de-fact applies to float, and long double (if it's
    different size than double).

    To handle above we introduce the __piecewise_distributions_storage<_Tp>
    struct, whose type nested typedef points to double in above two cases,
    and _Tp otherwise. The _StorageType is defined in terms of
    __piecewise_distributions_storage_t alias to above, and is then used
    in defintion of _M_den, _M_cp, and _M_m members. In consequence for
    extended floating point types (__float128, std::float16, ...) for which
    ABI can be changed, we store densitiees (and other values) as result_type.

    To avoid symbol conflicts, the param_type::densities member functions
    are marked with "__rt" ABI tag. The corresponding members of the
    distributions are modified to invoke param_type method, and marked
    as always_inline. For consistency intervals methods are adjusted same
    way.

    To preserve current behavior, the operators>> load densities
    as values of _StorageType.

    Finally, we introduce _GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS, that
    revers above changes, restoring old behavior for all floating point
    types. Additionally for the users accept above ABI change,
    we introduce a macro _GLIBCXX_USE_RESULT_TYPE_FOR_PIECEWISE_DENSITIES,
    that result in __piecewise_distributions_storage_t being unconditionally
    defined as _Tp, and thus adjust internal storage also for float and long
    double.

            PR libstdc++/82749

    libstdc++-v3/ChangeLog:

            * doc/xml/manual/using.xml
            (_GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS): Add entry.
            (_GLIBCXX_USE_RESULT_TYPE_FOR_PIECEWISE_DENSITIES): Add entry.
            * doc/html/manual/using_macros.html: Regenerate.
            * include/bits/random.h
            (__detail::__piecewise_distributions_storage)
            (__detail::__piecewise_distributions_storage_t)
            (piecewise_constant_distribution::_StorageType)
            (piecewise_linear_distribution::_StorageType): Define.
            (piecewise_constant_distribution::param_type::_M_den)
            (piecewise_constant_distribution::param_type::_M_cp)
            (piecewise_linear_distribution::param_type::_M_den)
            (piecewise_linear_distribution::param_type::_M_cp)
            (piecewise_linear_distribution::param_type::_M_m): Use _StorageType
            as element type.
            (piecewise_constant_distribution::param_type::densities)
            (piecewise_linear_distribution::param_type::densities)
            [!_GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS]: Change return type
            to vector<result_type>, mark with "__rt" ABI tag, and adjust
            implementation.
            (piecewise_constant_distribution::param_type::intervals)
            (piecewise_linear_distribution::param_type::intervals): Use
            result_type alias in return type.
            (piecewise_constant_distribution::densities)
            (piecewise_linear_distribution::densities): Delegate to param_type
            method, additional change return type and  mark as always_inline
            if _GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS is not defined.
            (piecewise_constant_distribution::intervals)
            (piecewise_linear_distribution::intervals): Delegate to param_type
            method and use result_type alias in return type.
            * include/bits/random.tcc
            (operator<<(basic_ostream&, const
piecewise_constant_distribution&))
            (operator<<(basic_ostream&, const piecewise_linear_distribution&)):
            Parse vector of _StorageType for densities, to preserve behavior.
            *
testsuite/26_numerics/random/piecewise_constant_distribution/operators/accessors.cc:
            New test.
            *
testsuite/26_numerics/random/piecewise_linear_distribution/operators/accessors.cc:
            New test.
            *
testsuite/26_numerics/random/piecewise_constant_distribution/operators/accessors_exact.cc:
            Run accessors.cc with
_GLIBCXX_USE_RESULT_TYPE_FOR_PIECEWISE_DENSITIES.
            *
testsuite/26_numerics/random/piecewise_linear_distribution/operators/accessors_exact.cc:
            Likewise.
            *
testsuite/26_numerics/random/piecewise_constant_distribution/operators/accessors_fallback.cc:
            Run accessors.cc with _GLIBCXX_USE_OLD_PICEWISE_DISTRIBUTIONS.
            *
testsuite/26_numerics/random/piecewise_linear_distribution/operators/accessors_fallback.cc:
            Likewise.

    Reviewed-by: Jonathan Wakely <[email protected]>
    Signed-off-by: Tomasz KamiÅski <[email protected]>

Reply via email to