In the following code:
struct Data{
int i;
Data(int i) : i(i){}
};
void test_data(Data){}
void test(std::function<void()>){}
int main(){
test([](){}); // how does it possible?
test({ [](){} }); // there is no need for extra {}
test_data(1); // But this one not work!
test_data({1}); // This one ok.
}
How does it possible that I can simply pass lambda to a function, that accepts std::function and it will be fine, while I can't do the same with my custom Data?
P.S. As I understand there is some conversion operator from lambda to std::function. But lambda is compiler construction, and std::function is a library construct. And I see nothing special here in it http://ift.tt/2nYlDnF
Aucun commentaire:
Enregistrer un commentaire