Skip to content

Commit 3272d2e

Browse files
Dawn Perchikzygoloid
authored andcommitted
P1645R1 constexpr for <numeric> algorithms
Also fixes NB US 320 (C++20 CD).
1 parent 4115311 commit 3272d2e

File tree

2 files changed

+69
-66
lines changed

2 files changed

+69
-66
lines changed

source/algorithms.tex

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8552,18 +8552,20 @@
85528552
namespace std {
85538553
// \ref{accumulate}, accumulate
85548554
template<class InputIterator, class T>
8555-
T accumulate(InputIterator first, InputIterator last, T init);
8555+
constexpr T accumulate(InputIterator first, InputIterator last, T init);
85568556
template<class InputIterator, class T, class BinaryOperation>
8557-
T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
8557+
constexpr T accumulate(InputIterator first, InputIterator last, T init,
8558+
BinaryOperation binary_op);
85588559

85598560
// \ref{reduce}, reduce
85608561
template<class InputIterator>
8561-
typename iterator_traits<InputIterator>::value_type
8562+
constexpr typename iterator_traits<InputIterator>::value_type
85628563
reduce(InputIterator first, InputIterator last);
85638564
template<class InputIterator, class T>
8564-
T reduce(InputIterator first, InputIterator last, T init);
8565+
constexpr T reduce(InputIterator first, InputIterator last, T init);
85658566
template<class InputIterator, class T, class BinaryOperation>
8566-
T reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
8567+
constexpr T reduce(InputIterator first, InputIterator last, T init,
8568+
BinaryOperation binary_op);
85678569
template<class ExecutionPolicy, class ForwardIterator>
85688570
typename iterator_traits<ForwardIterator>::value_type
85698571
reduce(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
@@ -8577,27 +8579,27 @@
85778579

85788580
// \ref{inner.product}, inner product
85798581
template<class InputIterator1, class InputIterator2, class T>
8580-
T inner_product(InputIterator1 first1, InputIterator1 last1,
8581-
InputIterator2 first2, T init);
8582+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
8583+
InputIterator2 first2, T init);
85828584
template<class InputIterator1, class InputIterator2, class T,
85838585
class BinaryOperation1, class BinaryOperation2>
8584-
T inner_product(InputIterator1 first1, InputIterator1 last1,
8585-
InputIterator2 first2, T init,
8586-
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
8586+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
8587+
InputIterator2 first2, T init,
8588+
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
85878589

85888590
// \ref{transform.reduce}, transform reduce
85898591
template<class InputIterator1, class InputIterator2, class T>
8590-
T transform_reduce(InputIterator1 first1, InputIterator1 last1,
8591-
InputIterator2 first2, T init);
8592+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
8593+
InputIterator2 first2, T init);
85928594
template<class InputIterator1, class InputIterator2, class T,
85938595
class BinaryOperation1, class BinaryOperation2>
8594-
T transform_reduce(InputIterator1 first1, InputIterator1 last1,
8595-
InputIterator2 first2, T init,
8596-
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
8596+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
8597+
InputIterator2 first2, T init,
8598+
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
85978599
template<class InputIterator, class T,
85988600
class BinaryOperation, class UnaryOperation>
8599-
T transform_reduce(InputIterator first, InputIterator last, T init,
8600-
BinaryOperation binary_op, UnaryOperation unary_op);
8601+
constexpr T transform_reduce(InputIterator first, InputIterator last, T init,
8602+
BinaryOperation binary_op, UnaryOperation unary_op);
86018603
template<class ExecutionPolicy,
86028604
class ForwardIterator1, class ForwardIterator2, class T>
86038605
T transform_reduce(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
@@ -8618,21 +8620,21 @@
86188620

86198621
// \ref{partial.sum}, partial sum
86208622
template<class InputIterator, class OutputIterator>
8621-
OutputIterator
8623+
constexpr OutputIterator
86228624
partial_sum(InputIterator first, InputIterator last,
86238625
OutputIterator result);
86248626
template<class InputIterator, class OutputIterator, class BinaryOperation>
8625-
OutputIterator
8627+
constexpr OutputIterator
86268628
partial_sum(InputIterator first, InputIterator last,
86278629
OutputIterator result, BinaryOperation binary_op);
86288630

86298631
// \ref{exclusive.scan}, exclusive scan
86308632
template<class InputIterator, class OutputIterator, class T>
8631-
OutputIterator
8633+
constexpr OutputIterator
86328634
exclusive_scan(InputIterator first, InputIterator last,
86338635
OutputIterator result, T init);
86348636
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
8635-
OutputIterator
8637+
constexpr OutputIterator
86368638
exclusive_scan(InputIterator first, InputIterator last,
86378639
OutputIterator result, T init, BinaryOperation binary_op);
86388640
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
@@ -8649,15 +8651,15 @@
86498651

86508652
// \ref{inclusive.scan}, inclusive scan
86518653
template<class InputIterator, class OutputIterator>
8652-
OutputIterator
8654+
constexpr OutputIterator
86538655
inclusive_scan(InputIterator first, InputIterator last,
86548656
OutputIterator result);
86558657
template<class InputIterator, class OutputIterator, class BinaryOperation>
8656-
OutputIterator
8658+
constexpr OutputIterator
86578659
inclusive_scan(InputIterator first, InputIterator last,
86588660
OutputIterator result, BinaryOperation binary_op);
86598661
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
8660-
OutputIterator
8662+
constexpr OutputIterator
86618663
inclusive_scan(InputIterator first, InputIterator last,
86628664
OutputIterator result, BinaryOperation binary_op, T init);
86638665
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
@@ -8681,7 +8683,7 @@
86818683
// \ref{transform.exclusive.scan}, transform exclusive scan
86828684
template<class InputIterator, class OutputIterator, class T,
86838685
class BinaryOperation, class UnaryOperation>
8684-
OutputIterator
8686+
constexpr OutputIterator
86858687
transform_exclusive_scan(InputIterator first, InputIterator last,
86868688
OutputIterator result, T init,
86878689
BinaryOperation binary_op, UnaryOperation unary_op);
@@ -8696,13 +8698,13 @@
86968698
// \ref{transform.inclusive.scan}, transform inclusive scan
86978699
template<class InputIterator, class OutputIterator,
86988700
class BinaryOperation, class UnaryOperation>
8699-
OutputIterator
8701+
constexpr OutputIterator
87008702
transform_inclusive_scan(InputIterator first, InputIterator last,
87018703
OutputIterator result,
87028704
BinaryOperation binary_op, UnaryOperation unary_op);
87038705
template<class InputIterator, class OutputIterator,
87048706
class BinaryOperation, class UnaryOperation, class T>
8705-
OutputIterator
8707+
constexpr OutputIterator
87068708
transform_inclusive_scan(InputIterator first, InputIterator last,
87078709
OutputIterator result,
87088710
BinaryOperation binary_op, UnaryOperation unary_op, T init);
@@ -8723,11 +8725,11 @@
87238725

87248726
// \ref{adjacent.difference}, adjacent difference
87258727
template<class InputIterator, class OutputIterator>
8726-
OutputIterator
8728+
constexpr OutputIterator
87278729
adjacent_difference(InputIterator first, InputIterator last,
87288730
OutputIterator result);
87298731
template<class InputIterator, class OutputIterator, class BinaryOperation>
8730-
OutputIterator
8732+
constexpr OutputIterator
87318733
adjacent_difference(InputIterator first, InputIterator last,
87328734
OutputIterator result, BinaryOperation binary_op);
87338735
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
@@ -8744,7 +8746,7 @@
87448746

87458747
// \ref{numeric.iota}, iota
87468748
template<class ForwardIterator, class T>
8747-
void iota(ForwardIterator first, ForwardIterator last, T value);
8749+
constexpr void iota(ForwardIterator first, ForwardIterator last, T value);
87488750

87498751
// \ref{numeric.ops.gcd}, greatest common divisor
87508752
template<class M, class N>
@@ -8798,10 +8800,10 @@
87988800
\indexlibraryglobal{accumulate}%
87998801
\begin{itemdecl}
88008802
template<class InputIterator, class T>
8801-
T accumulate(InputIterator first, InputIterator last, T init);
8803+
constexpr T accumulate(InputIterator first, InputIterator last, T init);
88028804
template<class InputIterator, class T, class BinaryOperation>
8803-
T accumulate(InputIterator first, InputIterator last, T init,
8804-
BinaryOperation binary_op);
8805+
constexpr T accumulate(InputIterator first, InputIterator last, T init,
8806+
BinaryOperation binary_op);
88058807
\end{itemdecl}
88068808

88078809
\begin{itemdescr}
@@ -8834,7 +8836,7 @@
88348836
\indexlibraryglobal{reduce}%
88358837
\begin{itemdecl}
88368838
template<class InputIterator>
8837-
typename iterator_traits<InputIterator>::value_type
8839+
constexpr typename iterator_traits<InputIterator>::value_type
88388840
reduce(InputIterator first, InputIterator last);
88398841
\end{itemdecl}
88408842

@@ -8870,7 +8872,7 @@
88708872
\indexlibraryglobal{reduce}%
88718873
\begin{itemdecl}
88728874
template<class InputIterator, class T>
8873-
T reduce(InputIterator first, InputIterator last, T init);
8875+
constexpr T reduce(InputIterator first, InputIterator last, T init);
88748876
\end{itemdecl}
88758877

88768878
\begin{itemdescr}
@@ -8902,8 +8904,8 @@
89028904
\indexlibraryglobal{reduce}%
89038905
\begin{itemdecl}
89048906
template<class InputIterator, class T, class BinaryOperation>
8905-
T reduce(InputIterator first, InputIterator last, T init,
8906-
BinaryOperation binary_op);
8907+
constexpr T reduce(InputIterator first, InputIterator last, T init,
8908+
BinaryOperation binary_op);
89078909
template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation>
89088910
T reduce(ExecutionPolicy&& exec,
89098911
ForwardIterator first, ForwardIterator last, T init,
@@ -8949,14 +8951,14 @@
89498951
\indexlibraryglobal{inner_product}%
89508952
\begin{itemdecl}
89518953
template<class InputIterator1, class InputIterator2, class T>
8952-
T inner_product(InputIterator1 first1, InputIterator1 last1,
8953-
InputIterator2 first2, T init);
8954+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
8955+
InputIterator2 first2, T init);
89548956
template<class InputIterator1, class InputIterator2, class T,
89558957
class BinaryOperation1, class BinaryOperation2>
8956-
T inner_product(InputIterator1 first1, InputIterator1 last1,
8957-
InputIterator2 first2, T init,
8958-
BinaryOperation1 binary_op1,
8959-
BinaryOperation2 binary_op2);
8958+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
8959+
InputIterator2 first2, T init,
8960+
BinaryOperation1 binary_op1,
8961+
BinaryOperation2 binary_op2);
89608962
\end{itemdecl}
89618963

89628964
\begin{itemdescr}
@@ -8987,9 +8989,9 @@
89878989
\indexlibraryglobal{transform_reduce}%
89888990
\begin{itemdecl}
89898991
template<class InputIterator1, class InputIterator2, class T>
8990-
T transform_reduce(InputIterator1 first1, InputIterator1 last1,
8991-
InputIterator2 first2,
8992-
T init);
8992+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
8993+
InputIterator2 first2,
8994+
T init);
89938995
\end{itemdecl}
89948996

89958997
\begin{itemdescr}
@@ -9025,11 +9027,11 @@
90259027
\begin{itemdecl}
90269028
template<class InputIterator1, class InputIterator2, class T,
90279029
class BinaryOperation1, class BinaryOperation2>
9028-
T transform_reduce(InputIterator1 first1, InputIterator1 last1,
9029-
InputIterator2 first2,
9030-
T init,
9031-
BinaryOperation1 binary_op1,
9032-
BinaryOperation2 binary_op2);
9030+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
9031+
InputIterator2 first2,
9032+
T init,
9033+
BinaryOperation1 binary_op1,
9034+
BinaryOperation2 binary_op2);
90339035
template<class ExecutionPolicy,
90349036
class ForwardIterator1, class ForwardIterator2, class T,
90359037
class BinaryOperation1, class BinaryOperation2>
@@ -9079,8 +9081,8 @@
90799081
\begin{itemdecl}
90809082
template<class InputIterator, class T,
90819083
class BinaryOperation, class UnaryOperation>
9082-
T transform_reduce(InputIterator first, InputIterator last, T init,
9083-
BinaryOperation binary_op, UnaryOperation unary_op);
9084+
constexpr T transform_reduce(InputIterator first, InputIterator last, T init,
9085+
BinaryOperation binary_op, UnaryOperation unary_op);
90849086
template<class ExecutionPolicy,
90859087
class ForwardIterator, class T,
90869088
class BinaryOperation, class UnaryOperation>
@@ -9132,11 +9134,11 @@
91329134
\indexlibraryglobal{partial_sum}%
91339135
\begin{itemdecl}
91349136
template<class InputIterator, class OutputIterator>
9135-
OutputIterator
9137+
constexpr OutputIterator
91369138
partial_sum(InputIterator first, InputIterator last,
91379139
OutputIterator result);
91389140
template<class InputIterator, class OutputIterator, class BinaryOperation>
9139-
OutputIterator
9141+
constexpr OutputIterator
91409142
partial_sum(InputIterator first, InputIterator last,
91419143
OutputIterator result, BinaryOperation binary_op);
91429144
\end{itemdecl}
@@ -9186,7 +9188,7 @@
91869188
\indexlibraryglobal{exclusive_scan}%
91879189
\begin{itemdecl}
91889190
template<class InputIterator, class OutputIterator, class T>
9189-
OutputIterator
9191+
constexpr OutputIterator
91909192
exclusive_scan(InputIterator first, InputIterator last,
91919193
OutputIterator result, T init);
91929194
\end{itemdecl}
@@ -9222,7 +9224,7 @@
92229224
\indexlibraryglobal{exclusive_scan}%
92239225
\begin{itemdecl}
92249226
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
9225-
OutputIterator
9227+
constexpr OutputIterator
92269228
exclusive_scan(InputIterator first, InputIterator last,
92279229
OutputIterator result, T init, BinaryOperation binary_op);
92289230
template<class ExecutionPolicy,
@@ -9287,7 +9289,7 @@
92879289
\indexlibraryglobal{inclusive_scan}%
92889290
\begin{itemdecl}
92899291
template<class InputIterator, class OutputIterator>
9290-
OutputIterator
9292+
constexpr OutputIterator
92919293
inclusive_scan(InputIterator first, InputIterator last,
92929294
OutputIterator result);
92939295
\end{itemdecl}
@@ -9322,7 +9324,7 @@
93229324
\indexlibraryglobal{inclusive_scan}%
93239325
\begin{itemdecl}
93249326
template<class InputIterator, class OutputIterator, class BinaryOperation>
9325-
OutputIterator
9327+
constexpr OutputIterator
93269328
inclusive_scan(InputIterator first, InputIterator last,
93279329
OutputIterator result, BinaryOperation binary_op);
93289330
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
@@ -9333,7 +9335,7 @@
93339335
ForwardIterator2 result, BinaryOperation binary_op);
93349336

93359337
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
9336-
OutputIterator
9338+
constexpr OutputIterator
93379339
inclusive_scan(InputIterator first, InputIterator last,
93389340
OutputIterator result, BinaryOperation binary_op, T init);
93399341
template<class ExecutionPolicy,
@@ -9411,7 +9413,7 @@
94119413
\begin{itemdecl}
94129414
template<class InputIterator, class OutputIterator, class T,
94139415
class BinaryOperation, class UnaryOperation>
9414-
OutputIterator
9416+
constexpr OutputIterator
94159417
transform_exclusive_scan(InputIterator first, InputIterator last,
94169418
OutputIterator result, T init,
94179419
BinaryOperation binary_op, UnaryOperation unary_op);
@@ -9486,7 +9488,7 @@
94869488
\begin{itemdecl}
94879489
template<class InputIterator, class OutputIterator,
94889490
class BinaryOperation, class UnaryOperation>
9489-
OutputIterator
9491+
constexpr OutputIterator
94909492
transform_inclusive_scan(InputIterator first, InputIterator last,
94919493
OutputIterator result,
94929494
BinaryOperation binary_op, UnaryOperation unary_op);
@@ -9500,7 +9502,7 @@
95009502
BinaryOperation binary_op, UnaryOperation unary_op);
95019503
template<class InputIterator, class OutputIterator,
95029504
class BinaryOperation, class UnaryOperation, class T>
9503-
OutputIterator
9505+
constexpr OutputIterator
95049506
transform_inclusive_scan(InputIterator first, InputIterator last,
95059507
OutputIterator result,
95069508
BinaryOperation binary_op, UnaryOperation unary_op,
@@ -9587,7 +9589,7 @@
95879589
\indexlibraryglobal{adjacent_difference}%
95889590
\begin{itemdecl}
95899591
template<class InputIterator, class OutputIterator>
9590-
OutputIterator
9592+
constexpr OutputIterator
95919593
adjacent_difference(InputIterator first, InputIterator last,
95929594
OutputIterator result);
95939595
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
@@ -9596,7 +9598,7 @@
95969598
ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);
95979599

95989600
template<class InputIterator, class OutputIterator, class BinaryOperation>
9599-
OutputIterator
9601+
constexpr OutputIterator
96009602
adjacent_difference(InputIterator first, InputIterator last,
96019603
OutputIterator result, BinaryOperation binary_op);
96029604
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
@@ -9679,7 +9681,7 @@
96799681
\indexlibraryglobal{iota}%
96809682
\begin{itemdecl}
96819683
template<class ForwardIterator, class T>
9682-
void iota(ForwardIterator first, ForwardIterator last, T value);
9684+
constexpr void iota(ForwardIterator first, ForwardIterator last, T value);
96839685
\end{itemdecl}
96849686

96859687
\begin{itemdescr}

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@
585585
#define @\defnlibxname{cpp_lib_constexpr_functional}@ 201907L // also in \libheader{functional}
586586
#define @\defnlibxname{cpp_lib_constexpr_iterator}@ 201811L // also in \libheader{iterator}
587587
#define @\defnlibxname{cpp_lib_constexpr_memory}@ 201811L // also in \libheader{memory}
588+
#define @\defnlibxname{cpp_lib_constexpr_numeric}@ 201911L // also in \libheader{numeric}
588589
#define @\defnlibxname{cpp_lib_constexpr_string}@ 201907L // also in \libheader{string}
589590
#define @\defnlibxname{cpp_lib_constexpr_string_view}@ 201811L // also in \libheader{string_view}
590591
#define @\defnlibxname{cpp_lib_constexpr_tuple}@ 201811L // also in \libheader{tuple}

0 commit comments

Comments
 (0)