如何检查空的 boost::accumulators acc 与否?
例如:
if (acc.isEmpty())//I don't know what function here
return 0;
else
return boost::accumulators::mean(acc).
因为如果它是空的,我会为 boost::accumulators::mean(acc) 得到 NaN。
如何检查空的 boost::accumulators acc 与否?
例如:
if (acc.isEmpty())//I don't know what function here
return 0;
else
return boost::accumulators::mean(acc).
因为如果它是空的,我会为 boost::accumulators::mean(acc) 得到 NaN。
您可以使用累加器count
:
if (boost::accumulators::count(acc) == 0)//I don't know what function here
return 0;
else
return boost::accumulators::mean(acc);
或者,您可以nan
通过调用简单地检查它是否是std::isnan
:
if(std::isnan(boost::accumulators::mean(acc))
return 0;
else
return boost::accumulators::mean(acc);