From 18797a3f329fa9bc1d47c4f9a39deeef05b20960 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Mon, 29 Apr 2024 19:28:35 +0200 Subject: [PATCH] added noexcept guarantees to cumulative stats calculation --- include/boost/unordered/detail/cumulative_stats.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/boost/unordered/detail/cumulative_stats.hpp b/include/boost/unordered/detail/cumulative_stats.hpp index 18f96d39..8be500c1 100644 --- a/include/boost/unordered/detail/cumulative_stats.hpp +++ b/include/boost/unordered/detail/cumulative_stats.hpp @@ -44,8 +44,12 @@ struct cumulative_stats_data struct welfords_algorithm /* 0-based */ { template - int operator()(T&& x,cumulative_stats_data& d)const + int operator()(T&& x,cumulative_stats_data& d)const noexcept { + static_assert( + noexcept(static_cast(x)), + "Argument conversion to double must not throw."); + d.m_prior=d.m; d.m+=(static_cast(x)-d.m)/static_cast(n); d.s+=(n!=1)* @@ -68,7 +72,7 @@ public: void reset()noexcept{*this=cumulative_stats();} template - void add(Ts&&... xs) + void add(Ts&&... xs)noexcept { static_assert( sizeof...(Ts)==N,"A sample must be provided for each sequence."); @@ -122,7 +126,7 @@ public: } template - void add(Ts&&... xs) + void add(Ts&&... xs)noexcept { lock_guard lck{mut}; super::add(std::forward(xs)...);