Originally Posted by
coffee_cup
1) why does found always return 0 eventhough the filename exists?
It shouldn't. However, I notice that your lambda is wrong. The "myStorage const& f" parameter declaration should be "singleFile const& f".
Originally Posted by
coffee_cup
2) I don't know how to pass an actual search string instead of the hardcoded approach as above with filename =="bla" :/ could you give me some hints by any chance?
Make use of a capture, e.g.,
Code:
std::string subject = "file1";
auto it = std::find_if(std::begin(myStorage), std::end(myStorage), [&subject](const singleFile& f)
{
return f.filename == subject;
});
though of course you presumably will not hard code the initialisation of subject
By the way, because of argument dependent (Koenig) lookup, you can write:
Code:
std::string subject = "file1";
auto it = std::find_if(begin(myStorage), end(myStorage), [&subject](const singleFile& f)
{
return f.filename == subject;
});
even without the using declarations/directive. (You can leave out the qualification for find_if too, but perhaps it makes sense to qualify it anyway).