tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
set_symmetric_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_SYMMETRIC_DIFFERENCE_HPP
5#define TETL_ALGORITHM_SET_SYMMETRIC_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/// Computes symmetric difference of two sorted ranges: the elements that
16/// are found in either of the ranges, but not in both of them are copied to the
17/// range beginning at destination. The resulting range is also sorted.
18template <typename InputIt1, typename InputIt2, typename OutputIt, typename Compare>
20 InputIt1 first1,
21 InputIt1 last1,
22 InputIt2 first2,
23 InputIt2 last2,
24 OutputIt destination,
25 Compare comp
26) -> OutputIt
27{
28 while (first1 != last1) {
29 if (first2 == last2) {
30 return etl::copy(first1, last1, destination);
31 }
32
33 if (comp(*first1, *first2)) {
34 *destination++ = *first1++;
35 } else {
36 if (comp(*first2, *first1)) {
37 *destination++ = *first2;
38 } else {
39 ++first1;
40 }
41 ++first2;
42 }
43 }
44 return etl::copy(first2, last2, destination);
45}
46
47template <typename InputIt1, typename InputIt2, typename OutputIt>
48constexpr auto set_symmetric_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt dest)
49 -> OutputIt
50{
51 return etl::set_symmetric_difference(first1, last1, first2, last2, dest, etl::less());
52}
53
54/// @}
55
56} // namespace etl
57
58#endif // TETL_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP
constexpr auto set_symmetric_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination, Compare comp) -> OutputIt
Definition set_symmetric_difference.hpp:19
constexpr auto set_symmetric_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt dest) -> OutputIt
Definition set_symmetric_difference.hpp:48
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15