Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until runtime.

This will work for any type with a < operator defined. Uses the standard library function `max_element()`.

#include <algorithm>
#include <cassert>
template<typename Ty> Ty max(unsigned int count, Ty values[]) {
assert(count > 0);
return *std::max_element(values, values + count);
}

SOURCE

Content is available under GNU Free Documentation License 1.2.

*Related Posts*