tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
max.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_MAX_HPP
5#define TETL_ALGORITHM_MAX_HPP
6
7#include <etl/_functional/less.hpp>
8
9namespace etl {
10
11/// \brief Returns the greater of a and b, using a compare function.
12/// \ingroup algorithm
13template <typename Type, typename Compare>
14[[nodiscard]] constexpr auto max(Type const& a, Type const& b, Compare comp) noexcept -> Type const&
15{
16 return comp(a, b) ? b : a;
17}
18
19/// \brief Returns the greater of a and b.
20/// \ingroup algorithm
21template <typename Type>
22[[nodiscard]] constexpr auto max(Type const& a, Type const& b) noexcept -> Type const&
23{
24 return etl::max(a, b, etl::less());
25}
26
27} // namespace etl
28
29#endif // TETL_ALGORITHM_MAX_HPP
constexpr auto max(Type const &a, Type const &b) noexcept -> Type const &
Returns the greater of a and b.
Definition max.hpp:22
constexpr auto max(Type const &a, Type const &b, Compare comp) noexcept -> Type const &
Returns the greater of a and b, using a compare function.
Definition max.hpp:14
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15