Reputation: 6595
here is my array
std::array<double, 64> fm_sim;
I want to find the maximum value in the array.
I can't use
double maxFmSim = std::max(fm_sim.begin(), fm_sim.end());
this is the error :expected an identifier
for now this is what I'm doing
double maxFmSim = fm_sim[0];
for (int i = 0; i < 64; i++)
{
if(fm_sim[i] > maxFmSim)
{
maxFmSim = fm_sim[i];
}
}
Is there a faster way/ other std/stl function which I can use in order to find the max value ?
Upvotes: 6
Views: 12431
Reputation: 118011
The function std::max
returns the greater value between two values. For a container you can use std::max_element
. Since this returns an iterator to the max element, you need to dereference it.
double maxFmSim = *std::max_element(fm_sim.begin(), fm_sim.end());
Upvotes: 18