tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
min_element.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_MIN_ELEMENT_HPP
4#define TETL_ALGORITHM_MIN_ELEMENT_HPP
5
7
8namespace etl {
9
13template <typename ForwardIt, typename Compare>
14[[nodiscard]] constexpr auto min_element(ForwardIt first, ForwardIt last, Compare comp) -> ForwardIt
15{
16 if (first == last) {
17 return last;
18 }
19
20 ForwardIt smallest = first;
21 ++first;
22 for (; first != last; ++first) {
23 if (comp(*first, *smallest)) {
24 smallest = first;
25 }
26 }
27 return smallest;
28}
29
33template <typename ForwardIt>
34[[nodiscard]] constexpr auto min_element(ForwardIt first, ForwardIt last) noexcept -> ForwardIt
35{
36 return etl::min_element(first, last, etl::less());
37}
38
39} // namespace etl
40
41#endif // TETL_ALGORITHM_MIN_ELEMENT_HPP
constexpr auto min_element(ForwardIt first, ForwardIt last, Compare comp) -> ForwardIt
Finds the smallest element in the range [first, last). Elements are compared using the given binary c...
Definition min_element.hpp:14
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14