tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
nth_element.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_NTH_ELEMENT_HPP
5#define TETL_ALGORITHM_NTH_ELEMENT_HPP
6
7#include <etl/_algorithm/sort.hpp>
8#include <etl/_utility/ignore_unused.hpp>
9
10namespace etl {
11
12/// \brief nth_element is a partial sorting algorithm that rearranges elements
13/// in `[first, last)` such that:
14/// - The element pointed at by nth is changed to whatever element would occur
15/// in that position if `[first, last)` were sorted.
16/// - All of the elements before this new nth element are less than or equal to
17/// the elements after the new nth element.
18///
19/// https://en.cppreference.com/w/cpp/algorithm/nth_element
20///
21/// \ingroup algorithm
22template <typename RandomIt, typename Compare>
23constexpr auto nth_element(RandomIt first, RandomIt nth, RandomIt last, Compare comp) -> void
24{
25 // TODO: Improve. Currently forwards to regular sort.
26 etl::ignore_unused(nth);
27 etl::sort(first, last, comp);
28}
29
30template <typename RandomIt>
31constexpr auto nth_element(RandomIt first, RandomIt nth, RandomIt last) -> void
32{
33 etl::ignore_unused(nth);
34 etl::sort(first, last);
35}
36
37} // namespace etl
38
39#endif // TETL_ALGORITHM_NTH_ELEMENT_HPP
constexpr auto nth_element(RandomIt first, RandomIt nth, RandomIt last, Compare comp) -> void
nth_element is a partial sorting algorithm that rearranges elements in [first, last) such that:
Definition nth_element.hpp:23
Definition adjacent_find.hpp:9
constexpr auto nth_element(RandomIt first, RandomIt nth, RandomIt last) -> void
Definition nth_element.hpp:31