If these are causing hangups, you are overengineering your code.
and then there's things that are wonderful to use even if it's terrifying to look at how it's implemented like std::forward which is used with vector.emplace_back.
there's also simple things like vector<unique_ptr<X>> being legal C++11 syntax instead of an illegal right shift operator.
bool batch_failed = std::any_of(
jobs.begin(), jobs.end(),
[](const auto & job) { return job.failed(); }
);
In C++03-plus-auto, you'd have to define an helper function or class: bool isJobFailed(const Job& job) {
return job.failed();
}
And then use find_if, I guess: auto last = jobs.end();
auto iter = std::find_if(
jobs.begin(), jobs.end(),
isJobFailed
);
bool batch_failed = (iter == last); jobs.Any(job => job.failed())
(Lambdas in C++ is one ridiculous example where I must use all the existing types of brackets in one expression: [](){}
is a lambda.)What humanrebar wrote is an algorithm that will work with any range of any type that has a 'failed()' member function.
Here's another formalisation:
auto batch_failed = [](auto const& batch) {
return std::any_of (begin (batch), end (batch),
[](auto& testcase) { return testcase.failed (); });
}
This function will basically work with anything.99% of the time, I work on the full container, why not providing an overload which let me write at least
bool batch_failed = std::any_of(jobs,
[](const auto & job) { return job.failed();}
);
Then, lambas are verbose.
I would like to have a simpler syntax like for simple lambas (no capture, single expression in the lamba body). job could be automatically typed with const auto&, or you could write it yourself if you wish. job => return job.failed();
And a the current one, which is more verbose, for more complex lambas (capture, several expressions in the body)I've edited my original comment to fix the error.
This means that (ignoring the mis-dating of the unique/shared_ptr) he already admitted, his comment is otherwise accurate.
He explicitly said his reference was C++03