使用空boost :: accumulators

时间:2015-02-15 07:31:51

标签: c++ boost nan boost-accumulators

如何检查空的boost :: accumulators是否?

例如:

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

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

1 个答案:

答案 0 :(得分:3)

您可以使用累加器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);