tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
inplace_merge.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_INPLACE_MERGE_HPP
4#define TETL_ALGORITHM_INPLACE_MERGE_HPP
5
9
10namespace etl {
11
24template <typename BidirIt, typename Compare>
25constexpr auto inplace_merge(BidirIt begin, BidirIt mid, BidirIt end, Compare comp) -> void
26{
27 auto left = begin;
28 auto right = mid;
29 while (left != mid and right != end) {
30 if (comp(*right, *left)) {
31 auto value = etl::move(*right);
32 etl::move_backward(left, mid, mid + 1);
33 *left = etl::move(value);
34 ++right;
35 ++mid;
36 } else {
37 ++left;
38 }
39 }
40}
41
43template <typename BidirIt>
44constexpr auto inplace_merge(BidirIt first, BidirIt mid, BidirIt last) -> void
45{
46 etl::inplace_merge(first, mid, last, etl::less());
47}
48
49} // namespace etl
50
51#endif // TETL_ALGORITHM_INPLACE_MERGE_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto move_backward(BidirIt1 first, BidirIt1 last, BidirIt2 destination) -> BidirIt2
Moves the elements from the range [first, last), to another range ending at destination....
Definition move_backward.hpp:24
constexpr auto inplace_merge(BidirIt begin, BidirIt mid, BidirIt end, Compare comp) -> void
Merges two consecutive sorted ranges [first, middle) and [middle, last) into one sorted range [first,...
Definition inplace_merge.hpp:25
constexpr auto end(C &c) -> decltype(c.end())
Returns an iterator to the end (i.e. the element after the last element) of the given container c or ...
Definition end.hpp:14
constexpr auto begin(C &c) -> decltype(c.begin())
Returns an iterator to the beginning of the given container c or array array. These templates rely on...
Definition begin.hpp:20
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14