Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
stable_sort.hpp
Go to the documentation of this file.
1#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_STABLE_SORT_HPP_
2#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_STABLE_SORT_HPP_
3
4// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
5// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
6
7// Copyright 2026, Toyota Motor Corporation
8//
9// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10
11// IWYU pragma: private, include <algorithm>
12// IWYU pragma: friend "stdlib_detail/.*"
13
14#include "arene/base/algorithm/detail/functional.hpp"
15#include "arene/base/algorithm/detail/traits.hpp"
16#include "arene/base/algorithm/stable_sort.hpp"
17#include "arene/base/compiler_support/cpp14_inline.hpp"
18#include "arene/base/stdlib_choice/enable_if.hpp"
19#include "arene/base/stdlib_choice/move.hpp"
20#include "arene/base/type_traits/is_compare.hpp"
21#include "arene/base/type_traits/is_movable.hpp"
22#include "arene/base/type_traits/is_swappable.hpp"
23#include "arene/base/type_traits/iterator_category_traits.hpp"
24
25namespace std {
26
27// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
28/// @brief sorts a range into ascending order
29///
30/// @tparam I iterator type
31/// @tparam C compare type
32/// @param first beginning of the range
33/// @param last end of the range
34/// @param comp comparison function object
35///
36/// @pre @c I must satisfy the random access iterator requirements.
37/// @pre @c I must be ValueSwappable.
38/// @pre the type of <c>*first</c> must be Movable.
39/// @pre <c>[first, last)</c> must be a valid range.
40/// @pre The expression <c>comp(r1, r2)</c> must be convertible to @c bool
41/// for every argument @c r1 and @c r2 of type @c RT, where @c RT is the
42/// reference type of @c I, regardless of value category, and must not modify
43/// @c r1 or @c r2.
44/// @pre comp must define a *strict weak ordering relation*. For values
45/// @c a, @c b, and @c c, the following properties must be satisfied:
46/// * irreflexivity: <c> comp(a, a) </c> is @c false
47/// * transitivity: if <c> comp(a, b) </c> and <c> comp(b, c) </c> are both
48/// @c true, then <c> comp(a, c) </c> is @c true
49/// * transitivity of incomparability: let <c> e(a, b) </c> be
50/// <c> !comp(a, b) && !comp(b, a) </c>, then @c e is transitive
51///
52/// Sorts the elements in the range <c> [first, last) </c> in non-descending
53/// order, specified by @c comp. The order of equal elements is guaranteed to
54/// be preserved.
55///
56/// @post <c> is_sorted(first, last, comp) </c> is @c true
57///
58/// @note Complexity <br>
59/// * Given N as <c> last - first </c>, worst case of <c> O(N * log(N)) </c>
60/// applications of @c comp.
61///
62/// @note This sorting algorithm is stable.
63///
64template <
65 class I,
66 class C,
67 class = enable_if_t<
72 >
73 >
74auto stable_sort(I first, I last, C comp) noexcept( //
75 arene::base::is_nothrow_invocable_v<decltype(arene::base::stable_sort), I&&, I&&, C&&>
76) -> void {
78}
79// parasoft-end-suppress AUTOSAR-M3_3_2-a
80
81/// @brief sorts a range into ascending order
82///
83/// @tparam I iterator type
84/// @param first beginning of the range
85/// @param last end of the range
86///
87/// @pre @c I must satisfy the random access iterator requirements.
88/// @pre @c I must be ValueSwappable.
89/// @pre the type of <c>*first</c> must be Movable.
90/// @pre <c>[first, last)</c> must be a valid range.
91/// @pre The expression <c>comp(r1, r2)</c> must be convertible to @c bool
92/// for every argument @c r1 and @c r2 of type @c RT, where @c RT is the
93/// reference type of @c I, regardless of value category, and must not modify
94/// @c r1 or @c r2.
95/// @pre comp must define a *strict weak ordering relation*. For values
96/// @c a, @c b, and @c c, the following properties must be satisfied:
97/// * irreflexivity: <c> comp(a, a) </c> is @c false
98/// * transitivity: if <c> comp(a, b) </c> and <c> comp(b, c) </c> are both
99/// @c true, then <c> comp(a, c) </c> is @c true
100/// * transitivity of incomparability: let <c> e(a, b) </c> be
101/// <c> !comp(a, b) && !comp(b, a) </c>, then @c e is transitive
102///
103/// Sorts the elements in the range <c> [first, last) </c> in non-descending
104/// order, specified by @c operator<. The order of equal elements is
105/// guaranteed to be preserved.
106///
107/// @post <c> is_sorted(first, last) </c> is @c true
108///
109/// @note Complexity <br>
110/// * Given N as <c> last - first </c>, worst case of <c> O(N * log(N)) </c>
111/// applications of @c operator<.
112///
113/// @note This sorting algorithm is stable.
114///
115template <
116 class I,
117 class = enable_if_t<
124 >
125 >
126auto stable_sort(I first, I last) noexcept( //
128) -> void {
130}
131
132} // namespace std
133
134#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_STABLE_SORT_HPP_
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827