-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalarray_extra_operations.cpp
59 lines (46 loc) · 1.33 KB
/
valarray_extra_operations.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <valarray>
#include <algorithm>
#include <functional>
#include <ranges>
template <typename T>
std::valarray<T> operator + (
const std::valarray<T>& arr,
const std::ranges::common_range auto& some_range) {
std::valarray<T> res(arr.size());
std::transform(
std::ranges::begin(arr), std::ranges::end(arr),
std::ranges::begin(some_range),
std::ranges::begin(res), std::plus<>{});
return res;
}
template <typename T>
std::valarray<T> operator - (
const std::valarray<T>& arr,
const std::ranges::common_range auto& some_range) {
std::valarray<T> res(arr.size());
std::transform(
std::ranges::begin(arr), std::ranges::end(arr),
std::ranges::begin(some_range),
std::ranges::begin(res), std::minus<>{});
return res;
}
template <typename T>
std::valarray<T>& operator += (
std::valarray<T>& arr,
const std::ranges::common_range auto& some_range) {
std::transform(
std::ranges::begin(arr), std::ranges::end(arr),
std::ranges::begin(some_range),
std::ranges::begin(arr), std::plus<>{});
return arr;
}
template <typename T>
std::valarray<T>& operator -= (
std::valarray<T>& arr,
const std::ranges::common_range auto& some_range) {
std::transform(
std::ranges::begin(arr), std::ranges::end(arr),
std::ranges::begin(some_range),
std::ranges::begin(arr), std::minus<>{});
return arr;
}