Hi. To find the maximum element in a container using the predicate form, do
we supply a less predicate (one whose operator()(lhs, rhs) returns true if
lhs < rhs), or a more predicate (one whose operator()(lhs, rhs) returns true
if lhs > rhs)?
I found something like this works, but want to confirm:
find = std::max_elemen t(v.begin(), v.end(), less());
where
// real struct and operator() in my application are more complex
struct less : std::binary_fun ction<int, int, bool> {
bool operator()(int lhs, int rhs) const { return lhs<rhs; }
};
Second, to find the maximum element, one could also use either of the
following, right?
find = std::max_elemen t(v.begin(), v.end(), less());
or
find = std::min_elemen t(v.begin(), v.end(), more());
Thanks!
we supply a less predicate (one whose operator()(lhs, rhs) returns true if
lhs < rhs), or a more predicate (one whose operator()(lhs, rhs) returns true
if lhs > rhs)?
I found something like this works, but want to confirm:
find = std::max_elemen t(v.begin(), v.end(), less());
where
// real struct and operator() in my application are more complex
struct less : std::binary_fun ction<int, int, bool> {
bool operator()(int lhs, int rhs) const { return lhs<rhs; }
};
Second, to find the maximum element, one could also use either of the
following, right?
find = std::max_elemen t(v.begin(), v.end(), less());
or
find = std::min_elemen t(v.begin(), v.end(), more());
Thanks!
Comment