S
Stephen Howe
Hi
If I had
vector<int> v;
I can do
if (!v.empty())
{
const int vmax = *max_element(v.begin(), v.end());
// further stuff with vmax
}
and this works. But suppose I had
struct compound
{
int a;
int b;
};
vector<compound> w;
I would like to do
if (!w.empty())
{
const int wmaxa = *max_element(w.begin(), w.end()); // max a
value
const int wmaxb = *max_element(w.begin(), w.end()); // max b
value
}
Thinking aloud, I presume I use the predicate version, pass different
predicates, dereference and take the a & b values, yes?
Thanks
Stephen Howe
If I had
vector<int> v;
I can do
if (!v.empty())
{
const int vmax = *max_element(v.begin(), v.end());
// further stuff with vmax
}
and this works. But suppose I had
struct compound
{
int a;
int b;
};
vector<compound> w;
I would like to do
if (!w.empty())
{
const int wmaxa = *max_element(w.begin(), w.end()); // max a
value
const int wmaxb = *max_element(w.begin(), w.end()); // max b
value
}
Thinking aloud, I presume I use the predicate version, pass different
predicates, dereference and take the a & b values, yes?
Thanks
Stephen Howe