3

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).

ekaterina
  • 33
  • 2
  • on some platforms the nan might be signalling (I"m not sure the standard specifies this) – sehe Feb 15 '15 at 12:11

1 Answers1

4

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);
Pradhan
  • 16,391
  • 3
  • 44
  • 59