return 是 c++ 中函数的 return 的正确值是否异常安全?

Is it exception-safe that return the right value which is return of function in c++?

return c++ 函数的 return 的正确值是异常安全的吗? 例如,

template<typename Iterator, typename T>
T my_accumulate(Iterator first, Iterator last) {
    return std::accumulate(first, last, T());
};

在上面的代码中,std::accumulate可以抛出。 如果 std::accumulate 抛出会发生什么? T() 会导致内存泄漏吗? 还是出于某种原因安全? 如何为此编写异常安全代码?

What happen if std::accumulate throws?

临时 T 被销毁(就像正常返回一样)并将异常传播给调用者。

T() can make memory leak?

除非 class T 本身严重损坏​​。

or is it safe for some reason?

该函数是异常安全的。