tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
set_union.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_SET_UNION_HPP
4#define TETL_ALGORITHM_SET_UNION_HPP
5
8
9namespace etl {
10
13
18template <typename InputIt1, typename InputIt2, typename OutputIt, typename Compare>
19constexpr auto
20set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination, Compare comp)
21 -> OutputIt
22{
23 for (; first1 != last1; ++destination) {
24 if (first2 == last2) {
25 return etl::copy(first1, last1, destination);
26 }
27 if (comp(*first2, *first1)) {
28 *destination = *first2++;
29 continue;
30 }
31
32 *destination = *first1;
33 if (not comp(*first1, *first2)) {
34 ++first2;
35 }
36 ++first1;
37 }
38 return etl::copy(first2, last2, destination);
39}
40
41template <typename InputIt1, typename InputIt2, typename OutputIt>
42constexpr auto set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination)
43 -> OutputIt
44{
45 return etl::set_union(first1, last1, first2, last2, destination, etl::less());
46}
47
49
50} // namespace etl
51
52#endif // TETL_ALGORITHM_SET_UNION_HPP
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
constexpr auto set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination, Compare comp) -> OutputIt
Constructs a sorted union beginning at destination consisting of the set of elements present in one o...
Definition set_union.hpp:20
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14