Consider the two lambda functions in the following VC++ 10.0 code:
template <typename T>
void eq(uint fieldno, T value) {
table* index_table = db.get_index_table(fieldno);
if (index_table == nullptr) return;
std::set<uint> recs;
index_table->scan_index<T>(value, [&](uint recno, T n)->bool {
if (n != value) return false;
recs.insert(recno);
return true;
});
add_scalar_hits(fieldno, recs).is_hit =
[=](tools::wsdb::field_instance_t& inst) {
return boost::get<T>(inst) == value;
};
}
In the first lambda function, I was forced to use the ->bool
return type specification whereas in the second lambda the compiler was perfectly happy to infer the return type.
My question is: when can the compiler infer the return type on a lambda? Is it only when you have a simple one-liner?