Why does this code make a compile error?
std::find_if(std::begin(some_list), std::end(some_list), [](const auto& item){
//some code
});
The error of course at "auto"? why is not possible to know the type automatically ? thanks
This is because as of C++11, lambda functions in C++ cannot be defined generically, therefore you cannot declare a parameter using auto. This has been added in the C++14 (and is already supported by some compilers).
However, you can achieve the same thing in C++11 using decltype(), in you case:
std::find_if(std::begin(some_list), std::end(some_list), [](decltype(*some_list.begin())& item){
return item > 4;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With