In C++20, many (most?) C++-standard-library algorithms have been made constexpr
. Yet - std::accumulate
has not.
It seems like it could have been:
template<class InputIt, class T>
constexpr T accumulate(InputIt first, InputIt last, T init)
{
for (; first != last; ++first) {
init = std::move(init) + *first;
}
return init;
}
So - is there a reason it wasn't constexpr
'ed as well?
Note: This question was motivated by my answer to this question on compile-time accumulation.
P1645R1 was actually adopted in the Belfast meeting for inclusion in C++20 in response to NB comment US 320.
As a result, all of the following algorithms will be constexpr
in C++20 (except for the overloads of them that take an ExecutionPolicy
):