I implemented this function but it still give the following error and I can't figure out why..
/usr/include/c++/4.8/bits/stl_algo.h:6325: error: no match for call to '(Farm::killHeaviestAnimalOnFarm()::__lambda0) (Animal*&, Animal*&)' if (__comp(*__result, *__first)) ^
I searched some examples on the internet and I cannot see what's the difference between mine..
My .cpp file had the following killHeaviestAnimalOnFarm
Animal *Farm::killHeaviestAnimalOnFarm()
{
auto minmax_widths = std::max_element(animals.begin(), animals.end(),
[] (Animal const& lhs, Animal const& rhs) {
return lhs.getWeight() < rhs.getWeight();
});
}
std::max_element is defined inside the header file and it returns an iterator pointing to the element with the largest value in the range [first, last).
max() returns the largest element from an iterable.
Temporary storage with /tmp The Lambda execution environment provides a file system for your code to use at /tmp. This space has a fixed size of 512 MB. The same Lambda execution environment may be reused by multiple Lambda invocations to optimize performance.
Best practices suggest that one separate the handler from the Lambda's core logic. Not only is it okay to add additional definitions, it can lead to more legible code and reduce waste--e.g. multiple API calls to S3.
If animals
is vector<Animal*>
then change your lambda function to :
auto minmax_widths = std::max_element(animals.begin(), animals.end(),
[] (Animal const * lhs, Animal const * rhs) {
return lhs->getWeight() < rhs->getWeight();
});
The alternative is to make animals
a vector<Animal>
in which case your lambda works as is.
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