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