我无法弄清楚为什么编译器抱怨这段代码的模板替换失败
struct Report {
double val;
vector<string> props;
};
template <typename T>
void solve(
const Report& report,
std::function<T(const double, const string&)> map) {
vector<T> results;
results.reserve(report.props.size());
for (const auto& prop : report.props) {
results.emplace_back(map(report.val, prop));
}
}
int main(int argc, char const *argv[]) {
solve(Report(), [](const double x, const string&y) -> int {
return 1;
});
return 0;
}
我收到以下编译错误
note: candidate template ignored: could not match 'function<type-parameter-0-0
(double, const std::__1::basic_string<char> &)>' against '(lambda at
test.cpp:29:18)'