tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
adjacent_difference.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_NUMERIC_ADJACENT_DIFFERENCE_HPP
3#define TETL_NUMERIC_ADJACENT_DIFFERENCE_HPP
4
8
9namespace etl {
10
16template <typename InputIt, typename OutputIt, typename BinaryOperation>
17constexpr auto adjacent_difference(InputIt first, InputIt last, OutputIt destination, BinaryOperation op) -> OutputIt
18{
19 if (first == last) {
20 return destination;
21 }
22
23 auto acc = *first;
24 *destination = acc;
25
26 while (++first != last) {
27 auto val = *first;
28 *++destination = op(val, etl::move(acc));
29 acc = etl::move(val);
30 }
31
32 return ++destination;
33}
34
36template <typename InputIt, typename OutputIt>
37constexpr auto adjacent_difference(InputIt first, InputIt last, OutputIt destination) -> OutputIt
38{
39 using value_t = typename etl::iterator_traits<InputIt>::value_type;
40 return etl::adjacent_difference(first, last, destination, etl::minus<value_t>());
41}
42
43} // namespace etl
44
45#endif // TETL_NUMERIC_ADJACENT_DIFFERENCE_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto adjacent_difference(InputIt first, InputIt last, OutputIt destination, BinaryOperation op) -> OutputIt
Computes the differences between the second and the first of each adjacent pair of elements of the ra...
Definition adjacent_difference.hpp:17
Definition adjacent_find.hpp:8
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:47
Function object for performing subtraction. Effectively calls operator- on two instances of type T....
Definition minus.hpp:14