From Jason Turner

[reduce]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpfci4yi_g/{from.md → to.md} +81 -0
tmp/tmpfci4yi_g/{from.md → to.md} RENAMED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Reduce <a id="reduce">[[reduce]]</a>
2
+
3
+ ``` cpp
4
+ template<class InputIterator>
5
+ typename iterator_traits<InputIterator>::value_type
6
+ reduce(InputIterator first, InputIterator last);
7
+ ```
8
+
9
+ *Effects:* Equivalent to:
10
+
11
+ ``` cpp
12
+ return reduce(first, last,
13
+ typename iterator_traits<InputIterator>::value_type{});
14
+ ```
15
+
16
+ ``` cpp
17
+ template<class ExecutionPolicy, class ForwardIterator>
18
+ typename iterator_traits<ForwardIterator>::value_type
19
+ reduce(ExecutionPolicy&& exec,
20
+ ForwardIterator first, ForwardIterator last);
21
+ ```
22
+
23
+ *Effects:* Equivalent to:
24
+
25
+ ``` cpp
26
+ return reduce(std::forward<ExecutionPolicy>(exec), first, last,
27
+ typename iterator_traits<ForwardIterator>::value_type{});
28
+ ```
29
+
30
+ ``` cpp
31
+ template<class InputIterator, class T>
32
+ T reduce(InputIterator first, InputIterator last, T init);
33
+ ```
34
+
35
+ *Effects:* Equivalent to:
36
+
37
+ ``` cpp
38
+ return reduce(first, last, init, plus<>());
39
+ ```
40
+
41
+ ``` cpp
42
+ template<class ExecutionPolicy, class ForwardIterator, class T>
43
+ T reduce(ExecutionPolicy&& exec,
44
+ ForwardIterator first, ForwardIterator last, T init);
45
+ ```
46
+
47
+ *Effects:* Equivalent to:
48
+
49
+ ``` cpp
50
+ return reduce(std::forward<ExecutionPolicy>(exec), first, last, init, plus<>());
51
+ ```
52
+
53
+ ``` cpp
54
+ template<class InputIterator, class T, class BinaryOperation>
55
+ T reduce(InputIterator first, InputIterator last, T init,
56
+ BinaryOperation binary_op);
57
+ template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation>
58
+ T reduce(ExecutionPolicy&& exec,
59
+ ForwardIterator first, ForwardIterator last, T init,
60
+ BinaryOperation binary_op);
61
+ ```
62
+
63
+ *Requires:*
64
+
65
+ - `T` shall be `MoveConstructible` (Table  [[tab:moveconstructible]]).
66
+ - All of `binary_op(init, *first)`, `binary_op(*first, init)`,
67
+ `binary_op(init, init)`, and `binary_op(*first, *first)` shall be
68
+ convertible to `T`.
69
+ - `binary_op` shall neither invalidate iterators or subranges, nor
70
+ modify elements in the range \[`first`, `last`\].
71
+
72
+ *Returns:* *GENERALIZED_SUM*(binary_op, init, \*i, ...) for every `i` in
73
+ \[`first`, `last`).
74
+
75
+ *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
76
+
77
+ [*Note 1*: The difference between `reduce` and `accumulate` is that
78
+ `reduce` applies `binary_op` in an unspecified order, which yields a
79
+ nondeterministic result for non-associative or non-commutative
80
+ `binary_op` such as floating-point addition. — *end note*]
81
+