tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
is_sorted_until.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3#ifndef TETL_ALGORITHM_IS_SORTED_UNTIL_HPP
4#define TETL_ALGORITHM_IS_SORTED_UNTIL_HPP
5
6#include <etl/_functional/less.hpp>
7
8namespace etl {
9
10/// \ingroup algorithm
11template <typename ForwardIt, typename Compare>
12[[nodiscard]] constexpr auto is_sorted_until(ForwardIt first, ForwardIt last, Compare comp) -> ForwardIt
13{
14 if (first != last) {
15 ForwardIt next = first;
16 while (++next != last) {
17 if (comp(*next, *first)) {
18 return next;
19 }
20 first = next;
21 }
22 }
23 return last;
24}
25
26/// \brief Examines the range `[first, last)` and finds the largest range
27/// beginning at `first` in which the elements are sorted in non-descending
28/// order.
29/// \ingroup algorithm
30template <typename ForwardIt>
31[[nodiscard]] constexpr auto is_sorted_until(ForwardIt first, ForwardIt last) -> ForwardIt
32{
33 return etl::is_sorted_until(first, last, etl::less());
34}
35
36} // namespace etl
37
38#endif // TETL_ALGORITHM_IS_SORTED_UNTIL_HPP
constexpr auto is_sorted_until(ForwardIt first, ForwardIt last) -> ForwardIt
Examines the range [first, last) and finds the largest range beginning at first in which the elements...
Definition is_sorted_until.hpp:31
constexpr auto is_sorted_until(ForwardIt first, ForwardIt last, Compare comp) -> ForwardIt
Definition is_sorted_until.hpp:12
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15