I was wondering if there is a concise way to find the maximum value of one of the elements in the tuple vector. for example, for the next, let's say I want to find the largest second tuple value in the tuple vector.
vector<tuple<int, int>> foo = { {12,1},{12,5},{5,6} };
The result should be 6.
One way I could do this is with something like:
vector<double> allFoo;
for (int i = 0; i != size(foo); i++) {
allFoo.emplace_back(get<1>(foo[i]));
}
double maxVal = *max_element(allFoo.begin(), allFoo.end());
I feel that, because, in fact, you are repeating things twice, can this be done much easier?
My typing skills are a bit limited and it seems like you should be able to do some kind of max_element directly on foo ...
source
share