C++26: more constexpr in the standard library
Published on: 2025-05-07 19:36:58
Last week, we discussed language features that are becoming constexpr in C++26. Today, let’s turn our attention to the standard library features that will soon be usable at compile time. One topic is missing: exceptions. As they need both core language and library changes, I thought they deserved their own post.
P2562R1: constexpr stable sorting
This paper proposes making std::stable_sort , std::stable_partition , std::inplace_merge , and their ranges counterparts usable in constant expressions. While many algorithms have become constexpr over the years, this family related to stable sorting had remained exceptions — until now.
The recent introduction of constexpr containers gives extra motivation for this proposal. If you can construct a container at compile time, it’s only natural to want to sort it there, too. More importantly, a constexpr std::vector can now support efficient, stable sorting algorithms.
A key question is whether the algorithm can meet its computational complexi
... Read full article.