相关疑难解决方法(0)

为什么C ++ 20中没有将std :: accumulate设为constexpr?

在C ++ 20中,已经制作了许多(大多数?)C ++标准库算法constexpr。然而- std::accumulate还没有

似乎是它可能是:

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;
}
Run Code Online (Sandbox Code Playgroud)

所以-是否也没有理由constexpr吗?

注意:这个问题是由动机我的回答这个问题的编译时间的积累。

c++ c++-standard-library accumulate c++20

19
推荐指数
1
解决办法
701
查看次数

标签 统计

accumulate ×1

c++ ×1

c++-standard-library ×1

c++20 ×1