The c++ reference for std::accumulate
does not mention any exception to be possibly thrown by std::accumulate
, still its definition does not contain noexcept
. Assuming one uses types and operations which do not throw, is safe to employ std::accumulate
in a member function declared as noexcept
, or does one incur in UB?
For example:
#include <iostream>
#include <numeric>
#include <vector>
class A {
std::vector<int> m_v;
public:
A(std::size_t N) : m_v(N, 1) { }
int sum() const noexcept { return std::accumulate(m_v.begin(), m_v.end(), 0); }
};
int main()
{
A x{3};
std::cout << x.sum() << std::endl;
return 0;
}
Is declaring A::sum()
as noexcept
a source of UB?