1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once


#include <iterator><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <functional><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <numeric>
#include <vector><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "internal/dev_env.hpp"
#include "internal/types.hpp"

#include "adaptor/valarray.hpp"


namespace uni {


template<class T, class container = valarray<T>>
struct adjacent_difference : container {
  public:
    explicit adjacent_difference() noexcept(NO_EXCEPT) {}

    template<
        std::input_iterator I, std::sentinel_for<I> S,
        class Operator = std::minus<T>
    >
    explicit adjacent_difference(I first, S last, const bool remove_first = true, const Operator op = std::minus<T>{}) noexcept(NO_EXCEPT) {
        this->resize(std::ranges::distance(first, last));
        std::vector<T> diff(this->size());
        std::adjacent_difference(first, last, std::ranges::begin(diff), op);
        if(remove_first) diff.erase(std::ranges::begin(diff));
        this->assign(std::ranges::begin(diff), std::ranges::end(diff));
    }
};

template<std::input_iterator I, std::sentinel_for<I> S>
explicit adjacent_difference(I, S) -> adjacent_difference<typename std::iterator_traits<I>::value_type>;


} // namespace uni