【问题标题】:Using empty boost::accumulators使用空的 boost::accumulators
【发布时间】:2015-04-15 22:22:28
【问题描述】:

如何检查空的 boost::accumulators acc 与否?

例如:

if (acc.isEmpty())//I don't know what function here
 return 0;
else 
 return boost::accumulators::mean(acc).

因为如果它是空的,我会得到 NaN for boost::accumulators::mean(acc)。

【问题讨论】:

  • 在某些平台上,nan 可能会发出信号(我不确定标准是否指定了这一点)

标签: c++ boost nan boost-accumulators


【解决方案1】:

你可以使用累加器count:

if (boost::accumulators::count(acc) == 0)//I don't know what function here
 return 0;
else 
 return boost::accumulators::mean(acc);

或者,您可以通过调用std::isnan 来简单地检查它是否是nan

 if(std::isnan(boost::accumulators::mean(acc))
    return 0;
 else
    return boost::accumulators::mean(acc);

【讨论】:

    猜你喜欢
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 2017-11-11
    • 2011-12-06
    • 2011-07-08
    • 1970-01-01
    相关资源
    最近更新 更多