Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_sorted.hpp
Go to the documentation of this file.
1
// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: defines std::is_sorted"
2
3
// Copyright 2026, Toyota Motor Corporation
4
//
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7
#
ifndef
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_SORTED_HPP_
8
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_SORTED_HPP_
9
10
// IWYU pragma: private, include <algorithm>
11
// IWYU pragma: friend "stdlib_detail/.*"
12
13
#
include
"arene/base/algorithm/detail/functional.hpp"
14
#
include
"arene/base/algorithm/detail/traits.hpp"
15
#
include
"arene/base/constraints.hpp"
16
#
include
"arene/base/iterator/advance.hpp"
17
#
include
"arene/base/type_traits/is_compare.hpp"
18
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
19
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
20
#
include
"stdlib/include/stdlib_detail/forward.hpp"
21
#
include
"stdlib/include/stdlib_detail/is_copy_assignable.hpp"
22
#
include
"stdlib/include/stdlib_detail/is_copy_constructible.hpp"
23
#
include
"stdlib/include/stdlib_detail/iterator_traits.hpp"
24
#
include
"stdlib/include/stdlib_detail/move.hpp"
25
26
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
27
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
28
29
namespace
std
{
30
31
// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
32
/// @brief Check if a range is sorted. Returns @c false if there are any pair of sequential elements @c i and @c j such
33
/// that @c comp(j,i) is @c true otherwise returns @c true
34
/// @tparam ForwardIterator The iterator type used to identify the range
35
/// @tparam Comparator The type of the comparator
36
/// @param first The start of the range
37
/// @param last The end of the range
38
/// @param comp The comparator
39
/// @return @c true if the range is sorted, @c false otherwise
40
/// @pre @c [first,last) must be a valid range
41
/// @pre @c comp(*first,*first) must be valid and return a boolean-testable result
42
/// @pre @c comp must provide a strict weak order over the elements of the range
43
template
<
44
typename
ForwardIterator
,
45
typename
Comparator
,
46
arene
::
base
::
constraints
<
47
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
48
enable_if_t
<
arene
::
base
::
is_compare_v
<
49
Comparator
&,
50
typename
std
::
iterator_traits
<
ForwardIterator
>::
reference
>>
51
> =
nullptr
>
52
auto
is_sorted
(
ForwardIterator
first
,
ForwardIterator
last
,
Comparator
comp
)
noexcept
(
53
noexcept
(
first
!=
last
) &&
//
54
noexcept
(
arene
::
base
::
advance
(
first
, 1)) &&
//
55
noexcept
(
comp
(*
first
, *
first
)) &&
//
56
is_nothrow_copy_constructible_v
<
ForwardIterator
> &&
//
57
is_nothrow_copy_assignable_v
<
ForwardIterator
>
58
) ->
bool
{
59
if
(
first
!=
last
) {
60
ForwardIterator
prev
{
first
};
61
arene
::
base
::
advance
(
first
, 1);
62
while
(
first
!=
last
) {
63
if
(
comp
(*
first
, *
prev
)) {
64
return
false
;
65
}
66
prev
=
first
;
67
arene
::
base
::
advance
(
first
, 1);
68
}
69
}
70
return
true
;
71
}
72
// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2
73
74
/// @brief Check if a range is sorted. Returns @c false if there are any pair of sequential elements @c i and @c j such
75
/// that @c j<i is @c true otherwise returns @c true
76
/// @tparam ForwardIterator The iterator type used to identify the range
77
/// @param first The start of the range
78
/// @param last The end of the range
79
/// @return @c true if the range is sorted, @c false otherwise
80
/// @pre @c [first,last) must be a valid range
81
/// @pre @c *first<*first must be valid and return a boolean-testable result
82
/// @pre Less-than comparison of elements must provide a strict weak order over the elements of the range
83
template
<
84
typename
ForwardIterator
,
85
arene
::
base
::
constraints
<
86
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
87
enable_if_t
<
arene
::
base
::
is_compare_v
<
88
decltype
(
arene
::
base
::
algorithm_detail
::
operator_less
)&,
89
typename
std
::
iterator_traits
<
ForwardIterator
>::
reference
>>> =
nullptr
>
90
auto
is_sorted
(
ForwardIterator
first
,
ForwardIterator
last
)
noexcept
(
91
noexcept
(
is_sorted
(
std
::
move
(
first
),
std
::
move
(
last
),
arene
::
base
::
algorithm_detail
::
operator_less
))
92
) ->
bool
{
93
return
is_sorted
(
std
::
move
(
first
),
std
::
move
(
last
),
arene
::
base
::
algorithm_detail
::
operator_less
);
94
}
95
96
}
// namespace std
97
98
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_SORTED_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
is_sorted.hpp
Generated by
1.13.2