I have this piece of code and I do not understand why do not works.
During the compilation, in the lines where I call run(), I get:
Candidate template ignored: could not match 'function<double (const type-parameter-0-0 &, const type-parameter-0-0 &)>' against 'double (*)(const data_t &, const data_t &)'
this is the code:
struct data_t {
double value1;
double value2;
};
double scoreValue1(const data_t & a, const data_t & b) { return a.value1 - b.value1; }
double scoreValue2(const data_t & a, const data_t & b) { return a.value2 * b.value2; }
template <class T>
void run(const std::vector<T> & dataA, const std::vector<T> & dataB, std::function<double(const T &, const T &)> function) {
double value = 0;
for(size_t i=0; i<dataA.size(); ++i)
value += function(dataA[i], dataB[i]);
std::cout << value << std::endl;
}
int main(int argc, const char * argv[]) {
std::vector<data_t> dataA;
std::vector<data_t> dataB;
run(dataA, dataB, scoreValue1);
run(dataA, dataB, scoreValue2);
return 0;
}