I can’t figure what I am doing wrong with this std::all_of call.
I have a class Statistics:
class Statistics {
public:
bool isDataSet() const { return m_data.size() > 0; }
private:
std::vector<double> m_data;
};
Each instance of Statistics class corresponds to a certain object.
In another function in a different file I want to display statistics only if data has been initialized in all Statistics instances. I want to use std::all_of function in the following manner:
if( std::all_of(m_stats.begin(), m_stats.end(), &Statistics::isDataSet) ) {
...
}
where std::vector<Statistics*> m_stats.
The compiler reports error in that the ‘predicate term does not evaluate to a function taking 1 arguments’. As far as I know, each class member passes this pointer as the first parameter, so Statistics::isDataSet() should actually be a function with 1 parameter. But std::all_of sees this wrong.
Am I wrong in my assumption that Statistics::isDataSet() should be accepted as a function with 1 parameter in std::all_of()?
use
or
instead of
&Statistics::isDataSetin call toall_of. latter expect a callable type (as predicate) and will pass an instance ofStatisticsto it. Specifying member-function w/o instance obviously not enough to make a call