tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
minmax.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_MINMAX_HPP
5#define TETL_ALGORITHM_MINMAX_HPP
6
7#include <etl/_functional/less.hpp>
8#include <etl/_utility/pair.hpp>
9
10namespace etl {
11
12/// \brief Returns the lowest and the greatest of the given values.
13/// \ingroup algorithm
14template <typename T, typename Compare>
15[[nodiscard]] constexpr auto minmax(T const& a, T const& b, Compare comp) -> pair<T const&, T const&>
16{
17 using return_type = pair<T const&, T const&>;
18 return comp(b, a) ? return_type(b, a) : return_type(a, b);
19}
20
21/// \brief Returns the lowest and the greatest of the given values.
22/// \ingroup algorithm
23template <typename T>
24[[nodiscard]] constexpr auto minmax(T const& a, T const& b) -> pair<T const&, T const&>
25{
26 return etl::minmax(a, b, etl::less());
27}
28
29} // namespace etl
30
31#endif // TETL_ALGORITHM_MINMAX_HPP
constexpr auto minmax(T const &a, T const &b, Compare comp) -> pair< T const &, T const & >
Returns the lowest and the greatest of the given values.
Definition minmax.hpp:15
constexpr auto minmax(T const &a, T const &b) -> pair< T const &, T const & >
Returns the lowest and the greatest of the given values.
Definition minmax.hpp:24
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37