Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
sort.hpp
Go to the documentation of this file.
1
// Copyright 2026, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_SORT_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_SORT_HPP_
7
8
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
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/sort.hpp"
17
#
include
"arene/base/type_traits/is_compare.hpp"
18
#
include
"arene/base/type_traits/is_invocable.hpp"
19
#
include
"arene/base/type_traits/is_movable.hpp"
20
#
include
"arene/base/type_traits/is_swappable.hpp"
21
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
22
#
include
"arene/base/type_traits/remove_cvref.hpp"
23
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
24
#
include
"stdlib/include/stdlib_detail/move.hpp"
25
26
namespace
std
{
27
28
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
29
/// @brief sorts a range into ascending order
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> pred(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 not guaranteed
54
/// to be preserved.
55
///
56
/// @post <c> is_sorted(first, last, comp) </c> is @c true
57
///
58
/// @note Complexity
59
/// Given N as <c> last - first </c>, <c> O(N * log(N)) </c> applications of
60
/// @c comp.
61
///
62
template
<
63
class
I
,
64
class
C
,
65
class
=
enable_if_t
<
66
arene
::
base
::
is_random_access_iterator_v
<
I
> &&
67
arene
::
base
::
is_swappable_v
<
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>> &&
68
arene
::
base
::
is_movable_v
<
arene
::
base
::
remove_cvref_t
<
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>>> &&
69
arene
::
base
::
is_compare_v
<
C
&,
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>>
70
>
71
>
72
auto
sort
(
I
first
,
I
last
,
C
comp
)
noexcept
(
//
73
arene
::
base
::
is_nothrow_invocable_v
<
decltype
(
arene
::
base
::
sort
),
I
&&,
I
&&,
C
&&>
74
) ->
void
{
75
return
arene
::
base
::
sort
(
std
::
move
(
first
),
std
::
move
(
last
),
std
::
move
(
comp
));
76
}
77
// parasoft-end-suppress AUTOSAR-M3_3_2-a
78
79
/// @brief sorts a range into ascending order
80
/// @tparam I iterator type
81
/// @param first beginning of the range
82
/// @param last end of the range
83
///
84
/// @pre @c I must satisfy the random access iterator requirements.
85
/// @pre @c I must be ValueSwappable.
86
/// @pre the type of <c>*first</c> must be Movable.
87
/// @pre <c>[first, last)</c> must be a valid range.
88
/// @pre The expression <c>r1 < r2</c> must be convertible to @c bool
89
/// for every argument @c r1 and @c r2 of type @c RT, where @c RT is the
90
/// reference type of @c I, regardless of value category, and must not modify
91
/// @c r1 or @c r2.
92
/// @pre @c operator< must define a *strict weak ordering relation*. For values
93
/// @c a, @c b, and @c c, the following properties must be satisfied:
94
/// * irreflexivity: <c> a < a </c> is @c false
95
/// * transitivity: if <c> a < b </c> and <c> b < c </c> are both
96
/// @c true, then <c> a < c </c> is @c true
97
/// * transitivity of incomparability: let <c> e(a, b) </c> be
98
/// <c> !(a < b) && !(b < a) </c>, then @c e is transitive
99
///
100
/// Sorts the elements in the range <c> [first, last) </c> in non-descending
101
/// order, specified by @c operator<. The order of equal elements is not
102
/// guaranteed to be preserved.
103
///
104
/// @note Complexity
105
/// Given N as <c> last - first </c>, <c> O(N * log(N)) </c> applications of
106
/// @c operator<.
107
///
108
template
<
109
class
I
,
110
class
=
enable_if_t
<
111
arene
::
base
::
is_random_access_iterator_v
<
I
> &&
112
arene
::
base
::
is_swappable_v
<
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>> &&
113
arene
::
base
::
is_movable_v
<
arene
::
base
::
remove_cvref_t
<
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>>> &&
114
arene
::
base
::
is_compare_v
<
115
decltype
(
arene
::
base
::
algorithm_detail
::
operator_less
)&,
116
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
I
>>
117
>
118
>
119
auto
sort
(
I
first
,
I
last
)
noexcept
(
//
120
arene
::
base
::
is_nothrow_invocable_v
<
decltype
(
arene
::
base
::
sort
),
I
&&,
I
&&,
decltype
(
arene
::
base
::
algorithm_detail
::
operator_less
)>
121
) ->
void
{
122
return
arene
::
base
::
sort
(
std
::
move
(
first
),
std
::
move
(
last
),
arene
::
base
::
algorithm_detail
::
operator_less
);
123
}
124
125
}
// namespace std
126
127
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_SORT_HPP_
std::hash<::arene::base::result< void, E > >::operator()
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
stdlib
include
stdlib_detail
sort.hpp
Generated by
1.13.2