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// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_SET_DIFFERENCE_HPP
5#define TETL_ALGORITHM_SET_DIFFERENCE_HPP
6
7#include <etl/_algorithm/copy.hpp>
8#include <etl/_functional/less.hpp>
9
10namespace etl {
11
12/// \ingroup algorithm
13/// @{
14
15/// \brief Copies the elements from the sorted range `[first1, last1)` which are
16/// not found in the sorted range `[first2, last2)` to the range beginning at
17/// destination. Elements are compared using the given binary comparison
18/// function `comp` and the ranges must be sorted with respect to the same.
19template <typename InputIt1, typename InputIt2, typename OutputIt, typename Compare>
20constexpr auto
21set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination, Compare comp)
22 -> OutputIt
23{
24 while (first1 != last1) {
25 if (first2 == last2) {
26 return etl::copy(first1, last1, destination);
27 }
28
29 if (comp(*first1, *first2)) {
30 *destination++ = *first1++;
31 } else {
32 if (not comp(*first2, *first1)) {
33 ++first1;
34 }
35 ++first2;
36 }
37 }
38 return destination;
39}
40
41template <typename InputIt1, typename InputIt2, typename OutputIt>
42constexpr auto set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination)
43 -> OutputIt
44{
45 return etl::set_difference(first1, last1, first2, last2, destination, etl::less());
46}
47
48/// @}
49
50} // namespace etl
51
52#endif // TETL_ALGORITHM_SET_DIFFERENCE_HPP
constexpr auto set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) -> OutputIt
Copies the elements from the sorted range [first1, last1) which are not found in the sorted range [fi...
Definition set_difference.hpp:42
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:21
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15