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#ifndef TETL_ALGORITHM_IS_SORTED_UNTIL_HPP
3#define TETL_ALGORITHM_IS_SORTED_UNTIL_HPP
4
6
7namespace etl {
8
10template <typename ForwardIt, typename Compare>
11[[nodiscard]] constexpr auto is_sorted_until(ForwardIt first, ForwardIt last, Compare comp) -> ForwardIt
12{
13 if (first != last) {
14 ForwardIt next = first;
15 while (++next != last) {
16 if (comp(*next, *first)) {
17 return next;
18 }
19 first = next;
20 }
21 }
22 return last;
23}
24
29template <typename ForwardIt>
30[[nodiscard]] constexpr auto is_sorted_until(ForwardIt first, ForwardIt last) -> ForwardIt
31{
32 return etl::is_sorted_until(first, last, etl::less());
33}
34
35} // namespace etl
36
37#endif // TETL_ALGORITHM_IS_SORTED_UNTIL_HPP
constexpr auto is_sorted_until(ForwardIt first, ForwardIt last, Compare comp) -> ForwardIt
Definition is_sorted_until.hpp:11
constexpr auto next(InputIt it, typename iterator_traits< InputIt >::difference_type n=1) -> InputIt
Return the nth successor of iterator it.
Definition next.hpp:14
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14