]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: add constexpr stable_partition
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Fri, 14 Mar 2025 23:15:36 +0000 (00:15 +0100)
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Thu, 27 Mar 2025 12:47:30 +0000 (13:47 +0100)
commitaba3018af8e025a62a87c704ccad6714b13bc811
tree02d7366a3ecf9cc6d76aead3292b61eefd94915f
parent698ef4b29d875b9ab8903e95633f1473a29c217b
libstdc++: add constexpr stable_partition

This completes the implementation of P2562R1 for C++26.

Unlike the other constexpr algorithms of the same family,
stable_partition does not have a constexpr-friendly version "ready to
use" during constant evaluation. In fact, it is not even available on
freestanding, because it always allocates a temporary memory buffer.

This commit implements the simplest possible strategy: during constant
evaluation allocate a buffer of length 1 on the stack, and use that as
a working area.

libstdc++-v3/ChangeLog:

* include/bits/algorithmfwd.h (stable_partition): Mark it
as constexpr for C++26.
* include/bits/ranges_algo.h (__stable_partition_fn): Likewise.
* include/bits/stl_algo.h (stable_partition): Mark it as
constexpr for C++26; during constant evaluation use a new
codepath where a temporary buffer of 1 element is used.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc
(stable_partition): Add constexpr.
* testsuite/25_algorithms/stable_partition/constexpr.cc: New test.
libstdc++-v3/include/bits/algorithmfwd.h
libstdc++-v3/include/bits/ranges_algo.h
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc
libstdc++-v3/testsuite/25_algorithms/stable_partition/constexpr.cc [new file with mode: 0644]