tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
merge.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_MERGE_HPP
4#define TETL_ALGORITHM_MERGE_HPP
5
8
9namespace etl {
10
14template <typename InputIt1, typename InputIt2, typename OutputIt, typename Compare>
15constexpr auto
16merge(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination, Compare comp) -> OutputIt
17{
18 for (; first1 != last1; ++destination) {
19 if (first2 == last2) {
20 return etl::copy(first1, last1, destination);
21 }
22 if (comp(*first2, *first1)) {
23 *destination = *first2;
24 ++first2;
25 } else {
26 *destination = *first1;
27 ++first1;
28 }
29 }
30 return etl::copy(first2, last2, destination);
31}
32
34template <typename InputIt1, typename InputIt2, typename OutputIt>
35constexpr auto merge(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) -> OutputIt
36{
37 return etl::merge(first1, last1, first2, last2, destination, etl::less());
38}
39
40} // namespace etl
41
42#endif // TETL_ALGORITHM_MERGE_HPP
constexpr auto merge(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination, Compare comp) -> OutputIt
Merges two sorted ranges [first1, last1) and [first2, last2) into one sorted range beginning at desti...
Definition merge.hpp:16
constexpr auto copy(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Copies the elements in the range, defined by [first, last), to another range beginning at destination...
Definition copy.hpp:18
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14