当调用时,为什么ranges ::累积的init as std :: Move(init)
Why does ranges::accumulate not pass init as std::move(init) when invoke?
在2018年3月17日的commetulate.hpp
的提交d5e9afc起通过一个范围时,init会得到 std::move
。
T operator()(Rng && rng, T init, Op op = Op{}, P proj = P{}) const
{
return (*this)(begin(rng), end(rng), std::move(init), std::move(op),
std::move(proj));
}
上面的代码将调用以下方式:
T operator()(I begin, S end, T init, Op op = Op{}, P proj = P{}) const
{
for(; begin != end; ++begin)
init = invoke(op, init, invoke(proj, *begin)); // why do we need this another copy of init?
return init;
}
我想知道为什么我们在调用调用之前需要另一个init的副本?
必须以任何方式过度这个启动,对吗?那么,为什么不首先将其撕掉呢?
init = invoke(op, std::move(init), invoke(proj, *begin));
此代码试图避免假设C 17。 std::move
-ing init
可能会对其进行修改(这就是《移动语义》的目的,归根结底(。这给我们留下了这样的东西:
init = /* An expression that maybe modifies init */;
这将导致C 17之前的不确定行为。范围V3也将自己作为C 11和C 14的库。
相关文章:
- GCC对可能有效的代码抛出init list生存期警告
- GLEW/GLUT:调用init并创建一个窗口后,取消初始化并重新初始化?
- 为什么我会" void value not ignored as it ought to be"?
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- 为什么 std::shared_ptr 被认为是"heavy"和"expensive",但 std::array "same perfprmance as plain (c-style) arrays
- 使用 std::ios_base::Init 正确初始化全局变量
- Pybind11: init<> with lambda
- 了解 Linux 虚拟内存:valgrind 的 massif 输出显示了有和没有 --pages-as-heap 的主要差异
- 编译错误:"lvalue required as left operand of assignment" 不确定原因
- 为什么别名声明不是有效的 init 语句(/simple-declaration)?
- 结构 init:字符**类型的标量初始值设定项两边的大括号
- 如何理解"Temporary objs are destroyed as the last step in evaluating the full-expression"?谁能用一些简单的例子来说明这
- Atom gpp编译器给出"'C:UsersadminUser' is not recognized as an internal or..."错误
- 为什么基于范围类型的大括号上循环init列表是非法的c++
- r-在Rcpp和C++之间转换矢量(使用Rcpp::as或Rcpp:::wrap)是否会创建一个新的矢量并复制元素
- template<class T, int N> void h(T const(&)[N]); as friend function
- 我正在"void value not ignored as it ought to be"我该怎么办?
- 是否可以使用"if constexpr"来声明具有不同类型和init-expr的变量
- Android Studio TextView Init C++
- 当调用时,为什么ranges ::累积的init as std :: Move(init)