为什么在C ++ 20中没有使std :: accumulate成为constexpr? [英] Why has std::accumulate not been made constexpr in C++20?
问题描述
在C ++ 20中,许多(大多数?)C ++标准库算法已被制成 constexpr
.但是- std :: accumulate
还没有./p>
好像是,它可能是:
template< class InputIt,class T>constexpr T累加(InputIt首先,InputIt最后,T init){for(; first!= last; ++ first){初始化= std :: move(init)+ * first;}返回init;}
所以-是否有没有同样使用 constexpr
的原因?
P1645R1 实际上是在贝尔法斯特会议上采用的响应NB评论 US 320 包含在C ++ 20中.
因此,以下所有算法将在C ++ 20中成为 constexpr
(它们的重载除外,它们的重载采用 ExecutionPolicy
):
- 积累
- 减少
- 内部产品
- transform_reduce
- partial_sum
- exclusive_scan
- inclusive_scan
- transform_exclusive_scan
- transform_inclusive_scan
- adjacent_difference
- iota
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
):
- accumulate
- reduce
- inner_product
- transform_reduce
- partial_sum
- exclusive_scan
- inclusive_scan
- transform_exclusive_scan
- transform_inclusive_scan
- adjacent_difference
- iota
这篇关于为什么在C ++ 20中没有使std :: accumulate成为constexpr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!