Using empty boost::accumulators

540 Views Asked by At

How to check an empty boost::accumulators acc or not?

For example:

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

Because if it's empty, i get NaN for boost::accumulators::mean(acc).

1

There are 1 best solutions below

0
Pradhan On BEST ANSWER

You could use the accumulator count:

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

Alternatively, you could simply check if it is nan by calling std::isnan:

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