Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) MinElementAbove

 

MinElementAbove is a math code snippet to get the std::min_element above a certain value.

 

//From http://www.richelbilderbeek.nl/CppMinElementAbove.htm
double MinElementAbove(const std::vector<double>& v, const double above)
{
  const double max = std::numeric_limits<double>::max();
  double lowest = max;
  const std::vector<double>::const_iterator j = v.end();
  std::vector<double>::const_iterator i = v.begin();
  for ( ; i!=j; ++i)
  {
    if (*i > above && *i < lowest)
    {
      lowest = *i;
    }
  }
  return (lowest != max ? lowest : above);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict