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
29namespace 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
43template <
44 typename ForwardIterator,
45 typename Comparator,
51 > = nullptr>
53 noexcept(first != last) && //
54 noexcept(arene::base::advance(first, 1)) && //
55 noexcept(comp(*first, *first)) && //
58) -> bool {
59 if (first != last) {
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
83template <
84 typename ForwardIterator,
89 typename std::iterator_traits<ForwardIterator>::reference>>> = nullptr>
95
96} // namespace std
97
98#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_SORTED_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