sort(_RAIter, _RAIter, _Compare);
template<typename _RAIter>
+ _GLIBCXX26_CONSTEXPR
void
stable_sort(_RAIter, _RAIter);
template<typename _RAIter, typename _Compare>
+ _GLIBCXX26_CONSTEXPR
void
stable_sort(_RAIter, _RAIter, _Compare);
template<random_access_iterator _Iter, sentinel_for<_Iter> _Sent,
typename _Comp = ranges::less, typename _Proj = identity>
requires sortable<_Iter, _Comp, _Proj>
+ _GLIBCXX26_CONSTEXPR
_Iter
operator()(_Iter __first, _Sent __last,
_Comp __comp = {}, _Proj __proj = {}) const
template<random_access_range _Range,
typename _Comp = ranges::less, typename _Proj = identity>
requires sortable<iterator_t<_Range>, _Comp, _Proj>
+ _GLIBCXX26_CONSTEXPR
borrowed_iterator_t<_Range>
operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const
{
/// This is a helper function for the merge routines.
template<typename _BidirectionalIterator, typename _Distance,
typename _Compare>
+ _GLIBCXX26_CONSTEXPR
void
__merge_without_buffer(_BidirectionalIterator __first,
_BidirectionalIterator __middle,
/// This is a helper function for the stable sorting routines.
template<typename _RandomAccessIterator, typename _Compare>
+ _GLIBCXX26_CONSTEXPR
void
__inplace_stable_sort(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
}
template<typename _RandomAccessIterator, typename _Compare>
+ _GLIBCXX26_CONSTEXPR
inline void
__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp)
return;
#if _GLIBCXX_HOSTED
+ if (__is_constant_evaluated())
+ {
+ std::__inplace_stable_sort(__first, __last, __comp);
+ return;
+ }
+
typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
// __stable_sort_adaptive sorts the range in two halves,
// so the buffer only needs to fit half the range at once.
* ordering after calling @p stable_sort().
*/
template<typename _RandomAccessIterator>
+ _GLIBCXX26_CONSTEXPR
inline void
stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
* relative ordering after calling @p stable_sort().
*/
template<typename _RandomAccessIterator, typename _Compare>
+ _GLIBCXX26_CONSTEXPR
inline void
stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp)
ftms = {
name = constexpr_algorithms;
+ values = {
+ v = 202306;
+ cxxmin = 26;
+ };
values = {
v = 201806;
cxxmin = 20;
#undef __glibcxx_want_constexpr_functional
#if !defined(__cpp_lib_constexpr_algorithms)
-# if (__cplusplus >= 202002L)
+# if (__cplusplus > 202302L)
+# define __glibcxx_constexpr_algorithms 202306L
+# if defined(__glibcxx_want_all) || defined(__glibcxx_want_constexpr_algorithms)
+# define __cpp_lib_constexpr_algorithms 202306L
+# endif
+# elif (__cplusplus >= 202002L)
# define __glibcxx_constexpr_algorithms 201806L
# if defined(__glibcxx_want_all) || defined(__glibcxx_want_constexpr_algorithms)
# define __cpp_lib_constexpr_algorithms 201806L
#ifndef __cpp_lib_constexpr_algorithms
# error "Feature-test macro for constexpr algorithms missing"
+#elif __cplusplus > 202302L
+# if __cpp_lib_constexpr_algorithms < 202306L
+# error "Feature-test macro for constexpr algorithms has wrong value"
+# endif
#elif __cpp_lib_constexpr_algorithms < 201806L
# error "Feature-test macro for constexpr algorithms has wrong value"
#endif
sort(_RAIter, _RAIter, _Compare);
template<typename _RAIter>
+ _GLIBCXX26_CONSTEXPR
void
stable_sort(_RAIter, _RAIter);
template<typename _RAIter, typename _Compare>
+ _GLIBCXX26_CONSTEXPR
void
stable_sort(_RAIter, _RAIter, _Compare);
--- /dev/null
+// { dg-do compile { target c++26 } }
+
+#include <algorithm>
+#include <array>
+#include <functional>
+
+constexpr auto
+createArray()
+{
+ return std::to_array({10, 0, 1, 2, 5, 6, 7, 8, 3, 4, 9, 11});
+}
+
+constexpr bool
+test01()
+{
+ auto ar = createArray();
+ std::stable_sort(ar.begin(), ar.end());
+ return std::is_sorted(ar.begin(), ar.end());
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ auto ar = createArray();
+ std::stable_sort(ar.begin(), ar.end(), std::greater<>());
+ return std::is_sorted(ar.begin(), ar.end(), std::greater<>());
+}
+
+static_assert(test02());
+
+constexpr bool
+test03()
+{
+ auto ar = createArray();
+ std::ranges::stable_sort(ar);
+ return std::ranges::is_sorted(ar);
+}
+
+static_assert(test03());
+
+constexpr bool
+test04()
+{
+ auto ar = createArray();
+ std::ranges::stable_sort(ar, std::ranges::greater());
+ return std::ranges::is_sorted(ar, std::ranges::greater());
+}
+
+static_assert(test04());
+
+constexpr bool
+test05()
+{
+ auto ar = createArray();
+ auto proj = [](int i) { return -i; };
+ std::ranges::stable_sort(ar, {}, proj);
+ return std::ranges::is_sorted(ar, {}, proj);
+}
+
+static_assert(test05());